Create a class named Rectangle. 1. There are two int instance variables: width and length. 2. Create three constructors. a. Take two arguments from a client to the instance variables. b. Take one argument from a client to the instance variables; set it as a square instead of rectangle. c. No-argument constructor. Set up the way to take user information from keyboard. 3. Create 7 methods. a. getWidth(): return width to caller. b. getLength(): return length to caller. c. setWidth(): take one argument to reset width. d. setLength(): take one argument to reset length. e. getArea(): calculate area of rectangle and return area to caller. f. getPerimeter(): calculate perimeter of rectangle and return perimeter to caller. g. toString(): return a String with the information about width, length, area, and perimter of the object to caller. II Create a class named Yard which inherits Rectangle. 1. There is one more double instance variable: unitPrice. 2. Create a constructor. 3. Create three methods. a. enlarge(): take two arguments to increase the width and length. b. getPay(): to calculate a payment for a yard work. The way to calculate is sum of the followed i. unitPrice * area of the rectangle. ii. unitPrice * perimeter of the rectangle. c. toString(): to return information about a yard work on unit price and total payment and call super's toString to get retangle information to caller. III. Create a class name YardTest to have a main method to create objects and test your methods. Create an object of Yard with three arguments. Use toString concept to print information about the object you just created. Call enlarge method with an argument. Print the information again. Create another object of Yard with one argument only. Print information about this object. (Optional) Create the third object of Yard with two arguments. Print information about the new object.( Optional)
I. Create a class named Rectangle.
1. There are two int instance variables: width and length.
2. Create three constructors.
a. Take two arguments from a client to the instance variables.
b. Take one argument from a client to the instance variables;
set it as a square instead of rectangle.
c. No-argument constructor. Set up the way to take user information from keyboard.
3. Create 7 methods.
a. getWidth(): return width to caller.
b. getLength(): return length to caller.
c. setWidth(): take one argument to reset width.
d. setLength(): take one argument to reset length.
e. getArea(): calculate area of rectangle and return area to caller.
f. getPerimeter(): calculate perimeter of rectangle and return perimeter to caller.
g. toString(): return a String with the information about width, length, area, and perimter of the object to caller.
II Create a class named Yard which inherits Rectangle.
1. There is one more double instance variable: unitPrice.
2. Create a constructor.
3. Create three methods.
a. enlarge(): take two arguments to increase the width and length.
b. getPay(): to calculate a payment for a yard work.
The way to calculate is sum of the followed
i. unitPrice * area of the rectangle.
ii. unitPrice * perimeter of the rectangle.
c. toString(): to return information about a yard work on unit price and total payment
and call super's toString to get retangle information to caller.
III. Create a class name YardTest to have a main method to create objects and test your methods.
- Create an object of Yard with three arguments.
- Use toString concept to print information about the object you just created.
- Call enlarge method with an argument.
- Print the information again.
- Create another object of Yard with one argument only. Print information about this object. (Optional)
- Create the third object of Yard with two arguments. Print information about the new object.( Optional)
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images