Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

iLAB STEPS SECTION 1: Rectangle.java Back to Top Write a class called Rectangle. It should have length and width attributes that default to 1 if they...

iLAB STEPS

SECTION 1: Rectangle.java

Back to Top

Write a class called Rectangle. It should have length and width attributes that default to 1 if they are not set. It should have appropriate get and set methods for getting and setting the attributes. It should also have a perimeter() method that returns the perimeter of the rectangle. It should also have an area() method that returns the area of the rectangle. It should also have a getType() method that either returns a String with the value of "Rectangle" or prints that string value out.

SECTION 2: Square.java

Back to Top

Write a class called Square that is a child class of Rectangle. A square is a rectangle with equal sides. It should inherit the perimeter() and area() methods. It should also inherit the get and set methods for each attribute, if that is appropriate. The Square class should override the getType() method from the superclass so that it returns or outputs "Square."

SECTION 3: TestDriver.java

Back to Top

Write a class called TestDriver that demonstrates all of the code in your Rectangle class and your Square class. The TestDriver class should do the following:

  1. Create a Rectangle and a Square.
  2. Go into a loop where it asks the user if they want a Rectangle or Square.
  3. Read user answer.
  4. If user wants to quit, then exit the program.
  5. If user wants a Rectangle, ask user for width and length. If user wants a Square, ask user for the length of one side.
  6. Display the type (Rectangle or Square), the length, width, area, and perimeter.
  7. Return to Step 2.
Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question