Write a program FourMethods.java
that has a main()
and four other methods as described below. The main()
program call the four methods as needed and display the results.
giveInstructions()
. It takes no parameters, and it returns no values. It just prints out an explanation that the program is going to calculate the area of a square.getInput()
. It takes no parameters. It creates a Scanner object, asks the user to enter the length of one side of a square, and returns that value to the main program (where it is stored in a variable).calculateArea()
. It takes a parameter for the length of one side of a square, does a calculation to determine the area, and returns that result to the main program. It doesn't print anything.display()
. It takes a parameter for the result of the calculation and prints it out on the screen. It doesn't return anything.How could we modify these methods to calculate and print the area of a rectangle, where the lengths of the two sides are different? Java only allows a single return value from a method, so we can't return both length and width.
HINT: Is there some way that we can encapsulate those two values into a single object? An Array
or ArrayList
could be used to hold the two values, or a Pair
object could store the two values.