Menu

[Solved]Java Exercise Continuation Last One Create New Project New Main Class Usual Copy Rectangle Q37228157

In Java, This exercise is a continuation of the last one. Createa new project and a new main class as
usual. Now copy the Rectangle class from the last exercise to thisone which is.

public static void PrintRectangleInformation(Rectangle r){
System.out.println(“Height: ” + r.getHeight());
System.out.println(“Width: ” + r.getWidth());
System.out.println(“Area: ” + r.Area());
System.out.println(“Perimeter: ” + r.Perimeter());
if (r.isSquare())
System.out.println(“The rectangle is a square.”);
else
System.out.println(“The rectangle is not a square.”);

In the constructor
and the setWidth and setHeight methods, add in data validitychecking. If either the
width or the height comes in as less than 0 set it to 0.
In the main le:
(a) Copy the PrintRectangleInformation method over from the lastproject.
(b) Insert the following code into the main itself, note that thereare segments where you
need to gure out the code to insert (All the lines that are<<< … >>>).
Scanner kb = new Scanner(System.in);
System.out.println(“Test the data checking:”);
Rectangle rect = new Rectangle(-5, 3);
System.out.println(rect);
rect.setHeight(3);
System.out.println(rect);
rect.setWidth(-7);
System.out.println(rect);
rect.setHeight(-2);
rect.setWidth(7);
System.out.println(rect);
rect.setHeight(2);
System.out.println(rect);
System.out.println();
System.out.print(“Input the number of rectangles to use: “);
int n = kb.nextInt();
<<< Create an array of Rectangles of size n>>>
<<< Populate the array with randon rectanges with heightand width between 0 and 10 >>>
<<< Print out the array elements using the printlnfunction. >>>
<<< Print out the array elements using thePrintRectangleInformation function. >>>
<<< Find the rectangle with the largest area.>>>
<<< Print out the rectangle with maximum area using thePrintRectangleInformation function.
>>>
Run the program and you should get output like the following.
Test the data checking:
Rectangle Data: Width = 3.0 Height = 0.0
Rectangle Data: Width = 3.0 Height = 3.0
Rectangle Data: Width = 0.0 Height = 3.0
Rectangle Data: Width = 7.0 Height = 0.0
Rectangle Data: Width = 7.0 Height = 2.0
Input the number of rectangles to use: 10
Rectangle Data: Width = 9.696818626215295 Height =0.9044132908992675
Rectangle Data: Width = 1.7602156834998417 Height =1.5809235848418013
Rectangle Data: Width = 7.640322348926541 Height =3.766074692710226
Rectangle Data: Width = 6.441988716131148 Height =2.638859786016136
Rectangle Data: Width = 7.26403560607042 Height =1.9741348052055896
Rectangle Data: Width = 7.198309913410638 Height =3.483279146041701
Rectangle Data: Width = 0.03656638925011224 Height =3.649612048452233

Rectangle Data: Width = 8.52023236686162 Height =1.611220372055121
Rectangle Data: Width = 1.2849577138945434 Height =8.517524417189877
Rectangle Data: Width = 2.6143118169966795 Height =3.167500517890417
Height: 0.9044132908992675
Width: 9.696818626215295
Area: 8.76993164498869
Perimeter: 21.202463834229125
The rectangle is not a square.
Height: 1.5809235848418013
Width: 1.7602156834998417
Area: 2.782766488453331
Perimeter: 6.682278536683286
The rectangle is not a square.
Height: 3.766074692710226
Width: 7.640322348926541
Area: 28.774024642440597
Perimeter: 22.812794083273534
The rectangle is not a square.
Height: 2.638859786016136
Width: 6.441988716131148
Area: 16.999504964968203
Perimeter: 18.161697004294567
The rectangle is not a square.
Height: 1.9741348052055896
Width: 7.26403560607042
Area: 14.340185516196296
Perimeter: 18.476340822552018
The rectangle is not a square.
Height: 3.483279146041701
Width: 7.198309913410638
Area: 25.07372280812852
Perimeter: 21.363178118904678
The rectangle is not a square.
Height: 3.649612048452233
Width: 0.03656638925011224
Area: 0.13345313477560386
Perimeter: 7.372356875404691
The rectangle is not a square.
Height: 1.611220372055121
Width: 8.52023236686162
Area: 13.727971964130864
Perimeter: 20.26290547783348
The rectangle is not a square.
Height: 8.517524417189877
Width: 1.2849577138945434
Area: 10.944658703153257
Perimeter: 19.604964262168842
The rectangle is not a square.
Height: 3.167500517890417
Width: 2.6143118169966795
Area: 8.28083403426402
Perimeter: 11.563624669774192
The rectangle is not a square.
The rectangle with the maximum area is at index 2
The area of rectangle 2 is 28.774024642440597

Expert Answer


Answer to In Java, This exercise is a continuation of the last one. Create a new project and a new main class as usual. Now copy t… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *