Answered step by step
Verified Expert Solution
Link Copied!

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):

image text in transcribedimage text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions