Question

(The Rectangle class)

Following the example of the Circle class in Section 8.2,
design a class named Rectangle to represent a rectangle. The class contains:

■ Two double data fields named width and height that specify the width and
height of the rectangle. The default values are 1 for both width and height.
■ A no-arg constructor that creates a default rectangle.
■ A constructor that creates a rectangle with the specified width and height.
■ A method named getArea() that returns the area of this rectangle.
■ A method named getPerimeter() that returns the perimeter.

Draw the UML diagram for the class and then implement the class. Write a test
program that creates two Rectangle objects—one with width 4 and height 40
and the other with width 3.5 and height 35.9. Display the width, height, area,
and perimeter of each rectangle in this order.

(The Rectangle class) Following the example of the Circle class in Section 8.2,
design a class named Rectangle to represent a rectangle. The class contains:
. Two double data fields named width and height that specify the width and
height of the rectangle. The default values are 1 for both width and height.
A no-arg constructor that creates a default rectangle
. A constructor that creates a rectangle with the specified width and height.
a A method named getArea) that returns the area of this rectangle.
. A method named getPerimeter) that returns the perimeter.
Draw the UML diagram for the class and then implement the class. Write a test
program that creates two Rectangle objects-one with width 4 and height 40
and the other with width 3.5 and height 35.9. Display the width, height, area,
and perimeter of each rectangle in this order.
SAMPLE RUN #0: java Rectangle
Standard Output
Hide Invisibles
The-area-of-a-4.0.x-48.อ-Rectangle-is-168.0
The.perimeter.of a.4.0.x.40.0 Rectangleis 88.0
The area of.a.3.5 x 35.9.Rectangle.is.125.64999999999999
The perimeter.of .a.3.5 x 35.9 Rectangle.is.78.8
expand button
Transcribed Image Text:(The Rectangle class) Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: . Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. A no-arg constructor that creates a default rectangle . A constructor that creates a rectangle with the specified width and height. a A method named getArea) that returns the area of this rectangle. . A method named getPerimeter) that returns the perimeter. Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects-one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order. SAMPLE RUN #0: java Rectangle Standard Output Hide Invisibles The-area-of-a-4.0.x-48.อ-Rectangle-is-168.0 The.perimeter.of a.4.0.x.40.0 Rectangleis 88.0 The area of.a.3.5 x 35.9.Rectangle.is.125.64999999999999 The perimeter.of .a.3.5 x 35.9 Rectangle.is.78.8
Expert Solution

Want to see the full answer?

Check out a sample Q&A here
Blurred answer
Students who’ve seen this question also like:
Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Not helpful? See similar books
Database System Concepts
Database System Concepts
Introduction. 1PE
marketing sidebar icon
Want to see this answer and more?
Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*
*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: . The following statement reates an anonymous type:

A: Anonymous type Anonymous types allow encapsulating a set of values in an object without defining a…

Q: Complete the following class to implement all the methods in the class

A: I have given an answer in step 2.

Q: Given the following class definition , what is the output of the shown main method?

A: PROGRAM: //Defining Data class class Data{     //Initializing variables   private int x=1;   private…

Q: A- Explain the difference between the Constructor and Destructors, Give an exampla B- What are…

A: Given: Difference between constructor and destructor. Characteristics of constructor.…

Q: How do you define a method? How do you invoke a method?

A: Answer : define a method : The only required elements of a method declaration are the method's…

Q: Q3:- A- Explain the difference between the Constructor and Destructors, Give an exampla B- What are…

A: Constructors  initialise an object. It is called when the object is created. As soon as the object…

Q: Which of the following can have only abstract method?

A: Which of the following can have only abstract method? a. Public class b. Interface c. Abstract…

Q: Could you tell me how to fix the error in testing the following code: class Employee: """ The…

A: In the second last line of the program use object to call member function of class Employee. result…

Q: Implement the design of the Author class so that the following output is produced:

A: Solution: Programming language used: Python   Program Code in Python: (Note: all necessary comments…

Knowledge Booster
Computer Science
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.
Recommended textbooks for you
  • 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)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
  • C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education
  • 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)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education