Question: Design a class named Rectangle to represent a rectangle using object-oriented concepts of abstraction, encapsulation and exception handling. Follow the example of the Circle class
Design a class named Rectangle to represent a rectangle using object-oriented concepts of abstraction, encapsulation and exception handling. Follow the example of the Circle class with exception as posted in Module 1 (ICE# 10.0 Circle With Exception), which is designed using object-oriented concepts and exception handling. Class Rectangle 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 data field number of Objects to count the number of Rectangles A no-arg constructor that creates a default rectangle. A constructor that creates a rectangle with the specified width and height. Setter and getter methods to set and get width and height A method named getArea() that returns the area of this rectangle. Area = width height. A method named getPerimeter() that returns the perimeter. Perimeter = 2* (width + height), Apply Exception handling in setter methods if height or width are set to 0 or negative values. . Program output: Draw the UML dingram for the class then implement the class. Write a TestRectangle program that creates three Rectangle objects one with width 4 and height 40. and a second one with width 3.5 and height 35.9. and a third one with width-2 and height 20. Display the width height, area, and perimeter of each rectangle and number of rectangles in this order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
