Write a Rectangle class. A Rectangle has properties of width and length. You construct a Rectangle object by providing the width and length in that order. If no width and length are provided to the constructor, construct a Rectangle with width 0.0 and length 0.0. We want to be able to get and set both the width and the length independently. We also want to be able to ask for the area of the rectangle and the perimeter of the rectangle. What will the object need to remember? width and length - those are the instance variables. Rectangle class has these constructors : public Rectangle() - Constructs a new rectangle with width and length of 0.0. public Rectangle(double width, double length) - Constructs a new rectangle with the given width and length. Remember that the job of the constructor is to initialize the instance variables. It has these methods. public double getWidth() - Gets the width of this Rectangle public double getLength() - Gets the length of this Rectangle public void setWidth(double aWidth) - Sets a new width for this Rectangle public void setLength(double aLength) - Sets a new length for this Rectangle   public double area() - Calculates and returns this Rectangle's area (product of width and length)   public double perimeter() - Calculates and returns this Rectangle's perimeter (sum of all four sides) public void printDimensions() - Displays the width and length of this Rectangle in the following format (to two decimal places): Width: 3.48 Height: 7.27 The methods and constructor are provided as stubs in the starter file. A stub has a method header and a body with no implementation.  The stub for an accessor returns 0 for numbers or null for objects like strings.  A stub for a mutator method has no body at all.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a Rectangle class. A Rectangle has properties of width and length. You construct a Rectangle object by providing the width and length in that order. If no width and length are provided to the constructor, construct a Rectangle with width 0.0 and length 0.0. We want to be able to get and set both the width and the length independently. We also want to be able to ask for the area of the rectangle and the perimeter of the rectangle.

What will the object need to remember? width and length - those are the instance variables.

Rectangle class has these constructors :

  • public Rectangle() - Constructs a new rectangle with width and length of 0.0.
  • public Rectangle(double width, double length) - Constructs a new rectangle with the given width and length. Remember that the job of the constructor is to initialize the instance variables.

It has these methods.

    • public double getWidth() - Gets the width of this Rectangle
    • public double getLength() - Gets the length of this Rectangle
    • public void setWidth(double aWidth) - Sets a new width for this Rectangle
    • public void setLength(double aLength) - Sets a new length for this Rectangle

 

  • public double area() - Calculates and returns this Rectangle's area (product of width and length)

 

  • public double perimeter() - Calculates and returns this Rectangle's perimeter (sum of all four sides)
  • public void printDimensions() - Displays the width and length of this Rectangle in the following format (to two decimal places):
    • Width: 3.48
    • Height: 7.27

The methods and constructor are provided as stubs in the starter file. A stub has a method header and a body with no implementation. 

  • The stub for an accessor returns 0 for numbers or null for objects like strings. 
  • A stub for a mutator method has no body at all. 
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education