ashim_ag

profileFadel2013
mrwjavaweek02example.java

/************************************************/ /* Your Name */ /* Week 2 Programming Example */ /* Due Date: ______________________________ */ /* CS 151- Introduction to Programming */ /************************************************/ // This program will accept the input of the width and length of a rectangle // and output the perimeter and area. //Pseudocode: //1) Input the length of the rectangle //2) Input the width of the rectangle //3) Calculate the perimeter = 2 * (length + width) //4) Calculate the area = length * width //5) Output the perimeter of the rectangle //6) Output the area of the rectangle import java.util.*; import java.text.*; public class mrwJavaWeek02Example { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); //Class reference to allow input from the console double length = 0; //Length of a rectangle double width = 0; //Width of a rectangle double perimeter = 0; //Perimeter of the rectangle double area = 0; //Area of the rectangle //Step 1 System.out.print("Input the length of the rectangle: "); length = stdIn.nextDouble(); //Step 2 System.out.print("Input the width of the rectangle: "); width = stdIn.nextDouble(); //Step 3 perimeter = 2 * (length + width); //Step 4 area = length * width; //Step 5 - Added blank lines with println() statements System.out.println(); System.out.println(); System.out.println("The perimeter of the rectangle is: " + perimeter); //Step 6 - Added blank lines with println() statements System.out.println(); System.out.println(); System.out.println("The area of the rectangle is: " + area); } //end main }