Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using java language Question 4: CLO9 (20 marks) a Create class rectangle with the following specifications: (10 marks) It has 2 instance variables (non-static fields):
Using java language
Question 4: CLO9 (20 marks) a Create class rectangle with the following specifications: (10 marks) It has 2 instance variables (non-static fields): length and width and one class variable (static field): sides, which has a fixed value of 4 (1.5 marks) final (2) Write one set method (setRectangle) for setting the two instance variables at the same time. The method has two parameters and should accept and assign the passed arguments only if they are greater than zero. Otherwise, the method should throw an illegal argument exception (3.5 marks). (3) Write a two-argument constructor for the class using the set method written in the previous part (2 marks). (4) Using the two-argument constructor, write a no-argument constructor that should initialize both of the instance variables with the default values of 1 (1.5 marks). (5) Using the two-argument constructor, write a one-argument constructor that should initialize the two instance variables with the value of that one argument (1.5 marks). c. Write a test class (driver) for class rectangle that: (6 marks) (1) Create a rectangle object (recl) with the no-argument constructor (2 marks). (2) Use the setRectangle method to reset the length and width of recl to 5 and 0, respectively. Make sure that your code can handle the "illegal argument exception" resulting from calling setRectangle with the given arguments (4 marks)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started