Question: specs for Rectangle Rectangle Class For this assignment you are going to write code for the following ONE class called: Rectangle Here are the specifications

specs for Rectangle

 

Rectangle Class

For this assignment you are going to write code for the following ONE class called:

Rectangle

Here are the specifications of class Rectangle:

This class has FIVE methods and two attributes. The attributes are:

private double width;

private double length;

Here are the headers of all five methods:

main method:

public static void main(String [] args)

mutators and accessors:

public void setLength(double ll) public double getLength() public void setWidth(double ll) public double getWidth()

The mutators and accessors do what the book/slides describe. the main method must produce the input/outout shown in the examples below

Here is the full code of the main method:

public static void main(String[] aaa)

{

Rectangle r1 = new Rectangle();

Rectangle r2 = new Rectangle();

Rectangle r3 = new Rectangle();

Scanner sc = new Scanner(System.in);

System.out.print("enter length for rectangle 1: ");

r1.setLength(sc.nextDouble());

System.out.print("enter width for rectangle 1: ");

r1.setWidth(sc.nextDouble());

System.out.print("enter length for rectangle 2: ");

r2.setLength(sc.nextDouble());

System.out.print("enter width for rectangle 2: ");

r2.setWidth(sc.nextDouble());

System.out.print("enter length for rectangle 3: ");

r3.setLength(sc.nextDouble());

System.out.print("enter width for rectangle 3: ");

r3.setWidth(sc.nextDouble());

System.out.println("now lets print the rectangles:");

System.out.println("1. width: " + r1.getWidth() + " " + " length: " + r1.getLength()); System.out.println("2. width: " + r2.getWidth() + " " + " length: " + r2.getLength()); System.out.println("3. width: " + r3.getWidth() + " " + " length: " + r3.getLength()); }

Restrictions

1. DO NOT WRITE ANY CONSTRUCTOR. If you don't know what that is yet that's good. You will learn that in the next module. 2. do not use the 'this' keyword. 3. you must create new Rectangle objects in the main method. 4. do not declare any double variables in the main method. (Note: the previous main method code satisfies items 3 and 4).

General

Compile your file by typing: javac Rectangle.java Run your program by typing: java Rectangle Test your code by typing the following command: java Test

Examples:

% java Rectangle enter length for rectangle 1: 1.1 enter width for rectangle 1: 2.2 enter length for rectangle 2: 3.3 enter width for rectangle 2: 4.4 enter length for rectangle 3: 5.5 enter width for rectangle 3: 6.6 now lets print the rectangles: 1. width: 2.2 length: 1.1 2. width: 4.4 length: 3.3 3. width: 6.6 length: 5.5 % java Rectangle enter length for rectangle 1: 1 enter width for rectangle 1: -1 enter length for rectangle 2: 2 enter width for rectangle 2: -2 enter length for rectangle 3: 3 enter width for rectangle 3: -3 now lets print the rectangles: 1. width: -1.0 length: 1.0 2. width: -2.0 length: 2.0 3. width: -3.0 length: 3.0 %

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!