Question: please write in java language and include UML diagram also below two are for sample reference please do it correctly as asked above,also include UML


Assignment #1 (2%) Posted on Jan 21, 2022 Due Date: Tuesday Jan 25, 2022, at 11:59 PM Late submission: 10% penalty per day until Friday January 28, 11:59 PM Submit to the Assignment#1 drop box in MSWord format file include screenshot of the program output 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, 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 by referring to the constructor with arguments using this keywork. 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). A method that returns number of rectangles objects Apply Exception handling in setter methods if height or width are set to 0 or negative values. Program output: Draw the UML diagram 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. Submission on Slate: Submit only one Single MSWord file containing text of the program code (not an image of the code) and other requirements as follow: 1. UML diagram of Rectangle class 2. Text of your code(single spaced), i.e., not an image of the code (Note: Apply class abstraction and encapsulation and create a test/driver class TestRectangle and a Rectangle class. 3. Include screen shot of your execution screen pasted below the text of your program code. Template of OO program with Exception 30.0 Samole Construct Class Circle with Abstraction. Enculation and Exception handling Program prints ratius and we UMED /Clans program Ordewinxeption Circler public class Circle The radius of the crede private double radius ** The number of the objects created private static int number objects-03 *** Construct a circle with radini public Ordet this. 1 /* Construct a circle with a specified radius public Carcelohlenewadi stadisteadust numberfect 1 **Return radius public double return Circle -radius: double - Numberoobiect: int Circle Ciecieradius: double - getkadin double + seadusradius double vold Number of beint petreadi: double *** Stanwradius Subite void selain double neurada throun elementi credent newRadius ndiusw.Radius: ese to wa * Return number public static int petierofotect returnumber *Return the area of this code" puble double treat return radius radix 2015, Driver Class Testinde public class Testire public static void main(Stringarell try! Circle crew Cirdek System.out.printl For Radius **e1.petradiol) + Areale ci get real 1 catch illegalArgumentfceptionell System.out.printed 1 try Circe new Circle (5 System.out.println Foto getRadius Area is getrek 1 catchillegalArgument Exceptioned System.out.printinje: 0 an of 2 Automatic Zoom View as Text Download >> /* Set a new radius public void setkadius double newRadiathrom leplepeon! newRadius radiusnewidius che thweweewegulegunetan **Return number of objects" public static int Number of objects return number of objects **Return the area of this circle public double petreat return radius radius 2.54159 1 1/ Driver Class Testirdejava public class Testire ! public static void main(String arpit try Circle ci-new Circle (5) System.out.printl For Radius: cietkadunD+Aruale cigarealik 1 catch (IllegalArumentExceptionell System.out.printinel try! Circle 2 new Circle (-5): System.out.println("For Radius: ** (2.petdin) - Recolettreal 1 catch (llegalArgumentException System.out.printlne try Circle .rw Circle for System.out.println("For Radiu: " + ch getradius) Avair**.getAreal catch (illegalArgumentaception System.out.println(ex: System.out.printialNumber of objects createst Circle pentrumbertObjects Sample run For Radius: 50 Area : 78.53975 java.lang. IllegalArgumentException: Radius is assigned. S. Radius cannot be zero or negative java.lang. Illegal ArgumentException Radius is assigned as cannot be pero or negative Number of objects created: 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
