/**
AreaRectangleExercise.java
CS 111A in-class exercise
Craig Persiko's class (modified from Gaddis book)
Please complete this program so it calculates and displays the area of a rectangle.
DO NOT CHANGE THE MAIN METHOD.
*/
import java.util.Scanner;
public class AreaRectangleExercise
{
public static void main(String[] args)
{
// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
double length, // The rectangle's length
width, // The rectangle's width
area; // The rectangle's area
// Get the rectangle's length from the user.
length = getLength();
// Get the rectangle's width from the user, using the Scanner object that's already been created in Main.
width = getWidth(keyboard);
// Get the rectangle's area.
area = getArea(length, width);
// Display the rectangle data.
displayData(length, width, area);
}
}
/* Add your code for the following methods, to produce the sample output shown below:
getLength - This method should ask the user to enter the rectangle's length, and then return that value as a double.
getWidth - This method should ask the user to enter the rectangle's width, and then return that value as a double.
getArea - This method should accept the rectangle's length and width as arguments, and return the rectangle's area. The area is calculated by multiplying the length by the width.
displayData - This method should accept the rectangle's length, width, and area as arguments, and display them in an appropriate message on the screen, formatted with 1 digit after the decimal point.
*/
/* Sample Output:
[cpersiko@fog cs111a]$ java RectangleArea
Enter the rectangle's length: 5
Enter the rectangle's width: 10
Length = 5.0
Width = 10.0
Area = 50.0
[cpersiko@fog cs111a]$ java RectangleArea
Enter the rectangle's length: 1.25
Enter the rectangle's width: 3.25
Length = 1.3
Width = 3.3
Area = 4.1
[cpersiko@fog cs111a]$
*/
syntax highlighted by Code2HTML, v. 0.9