Design a public class named Rectangle to represent a rectangle following the example of the Circle class we did in Lesson #5. The Rectangle class contains: • Data fields: o private double data field width with default value 2 o private double data field length with default value 3 • Two constructor methods: o A no-argument constructor that creates a default rectangle with the default values o A constructor that creates a rectangle with the specified width and length in the formal parameters • Instance methods: o A public method named getPerimeter() that returns the perimeter of the rectangle (double) o A public method named getArea() that returns the area of the rectangle (double) o Public getter methods to access the data fields, specifically: ▪ getWidth() ▪ getLength() o Public setter methods to set the data fields to values passed in ▪ setWidth (double newWidth) ▪ setLength(double newLength) INFO 1214 –Assignment 3 Page 2 Write a simple test program call TestRectangle like we did in class that creates three Rectangle objects: • rect1 with default values for width and length (call the non-argument constructor) • rect2 with width = 18.5 and length = 33.92 • rect3 with width default values for width and length (call the non-argument constructor) However, you will test the setter methods and set the width and length as follows: o Set the width as a random number between 5 and 10 (excluding 5 and 10) o Set the length as a random number between 10 and 20 (excluding 10 and 20) o Check out Slide #40 Lesson #3 to see how to generate random numbers between two numbers • For each rectangle, print out: o width, length, area, and perimeter o Print each element to 2 significant digits (they are all doubles)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Design a public class named Rectangle to represent a rectangle following the example of the Circle class we did in Lesson #5. The Rectangle class contains:
• Data fields:
o private double data field width with default value 2
o private double data field length with default value 3
• Two constructor methods:
o A no-argument constructor that creates a default rectangle with the default values
o A constructor that creates a rectangle with the specified width and length in the formal parameters
• Instance methods:
o A public method named getPerimeter() that returns the perimeter of the rectangle (double)
o A public method named getArea() that returns the area of the rectangle (double)
o Public getter methods to access the data fields, specifically:
▪ getWidth()
▪ getLength()
o Public setter methods to set the data fields to values passed in
▪ setWidth (double newWidth)
▪ setLength(double newLength)
INFO 1214 –Assignment 3
Page 2
Write a simple test program call TestRectangle like we did in class that creates three Rectangle objects:
• rect1 with default values for width and length (call the non-argument constructor)
• rect2 with width = 18.5 and length = 33.92
• rect3 with width default values for width and length (call the non-argument constructor) However, you will test the setter methods and set the width and length as follows:
o Set the width as a random number between 5 and 10 (excluding 5 and 10)
o Set the length as a random number between 10 and 20 (excluding 10 and 20)
o Check out Slide #40 Lesson #3 to see how to generate random numbers between two numbers
• For each rectangle, print out:
o width, length, area, and perimeter
o Print each element to 2 significant digits (they are all doubles)

Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY