Now that we have written our first program we can look at a bit more complicated programs.
- Download FirstClass.java http://www.cs.bath.ac.uk/~mdv/courses/Pre-Programming/FirstClass.javaand ConsoleReader.java http://www.cs.bath.ac.uk/~mdv/courses/Pre-Programming/ConsoleReader.java.
- Have a close look at the code for FirstClass: read the comments (the English text
with stars and slashes). ConsoleReader is used by FirstClass. No need to go through the code unless you want to
- Run the code a few times. (Do not to forget to compile first and to run the class with the main method)
- Test the code by providing correct and incorrect input.
- Did you notice the difference between a return value and no return
- Write a method in FirstClass that is capable of computing the average of
four numbers. Use double instead of int to allow decimals. Inform both the user
and the program of your result. Make sure you include a method call to the main method.
Use readDouble to obtain the user input.
Note: Make sure you re-compile if you make changes
- Documenting your code is essential for programmers. You want other to
be able to understand what you are doing. Therefore, document your method
in a similar style as the other methods.
- Find out what would happen if you would change the doubles you used