package uwstout.courses.cs144.labs.lab2; import java.util.Scanner; /** * This computes the area and perimeter of a rectangle given the rectangle's * length and width. * * @author turners * @version 1.0 * */ public class RectangleValues { /** * This computes the area and perimeter of a rectangle given the rectangle's * length and width. * * * @param args Command line arguments (not used) * * * Input: (length: 10, width: 10) Expected: (perim: 40, area: 100) * * Input: (length: 0, width: 9) Expected: (perim: 18, area: 0) * * Input: (length: -2, width: 4) Expected: (perim: 4, area: -8) * * * */ public static void main(String[] args) { double length; double width; double perimeter; double area; // Create an object to read in data from the keyboard Scanner scan = new Scanner(System.in); // prompt for and read in length and width System.out.println("Enter the length of the rectangle: "); length = scan.nextDouble(); System.out.println("Enter the width of the rectangle: "); width = scan.nextDouble(); // compute perimeter and area perimeter = 2 * (length + width); area = length * width; // output results System.out.println("For a " + length + " x " + width + " rectangle, the perimeter is " + perimeter + " and the area is " + area + "."); scan.close(); } }