Question 1:
Write a class Rectangle that has the following private attributes/fields:
· name → (String, should be final)
· side1 (double)
· side2 (double)
· side3 (double)
· side4 (double)
· noRectangles (int, should be static. This is a counter of the number of Rectangle objects).
2- Write the full-argument constructor, the no-argument constructor and the copy-constructor.
Note 1: the no-argument constructor and the copy-constructor need to call the full-argument constructor. The no-argument constructor sets name to “InternalNameX”, where X is the value of noRectangles, and it sets the sides to 1.0.
Note 2: validate the input in the full-argument constructor such that if the name is null it sets the attribute name to “InternalNameX”, where X is the value of noRectangles, and if the sides are not strictly positive, it sets them to 1.0. It also must check the values of the sides constitute a rectangle (side1 equals sides3 and side2 equals side4). If not, an IllegalArgumentException is generated.
3- Write the getters and setters of all the attributes.
Note 3: validate the input in the setters according to Note 1.
4- Assuming the values of the sides constitute lengths in meter, overload two methods computeArea and computePerimeter (the return type of both is double) as follows:
· If they take no argument they compute the area and the perimter in meter.
· If they take one argument, then they check if the argument is “cm” (case insensitive) they return the area and the perimeter in centimeter, and if the argument is “inch” (case insensitive) they return the area and perimeter in inch. If the argument is none of these values, they throw an IllegalArgumentException.
Question 2:
1- Write a test class named “PractisingClasses” as follows:
· It prints the following menu to the user:
Please choose one of the following options:
1. Create a default rectange.
2. Create a defined rectangle.
3. Exit.
Enter your choice:
· It reads the user input, if the input is 1, it creates a rectangle using the no-argument constructor. If the input is 2, the following form will be given to the user to fill:
Enter name:
Enter the length of the first side in meters:
Enter the length of the second side in meters:
Enter the length of the third side in meters:
Enter the length of the forth side in meters:
When the user enters a name that already exists, or a name that starts with “InternalName”(case insensitive), an error message is dipalyed to him asking him to enter another name. As follows:
Enter name: InternalName66
ERROR: you cannot choose a name that starts with“InternalName”, or a name that already exists, please choose another name:
Enter name:
Note 5: Create an array and add in it any rectangle object that has been created.
· When the user choose 3 in the main menu, the program prints the name and the area in meter, centimeter and inch for each rectangle. It also prints the name and the area of the largest rectangle and the smallest rectangle (with respect to the area).
Note 6: Print the decimal numbers in two decimal points format.
Note 4: to convert from meter to inch multiply by 39.37.
Question1:
Question2:
need an explanation for this answer? contact us directly to get an explanation for this answer