Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Class Rectangle Create an object that stores information about a rectangle, leng

ID: 3597650 • Letter: C

Question


Class Rectangle Create an object that stores information about a rectangle, length and width Includes a method that increases length by a number Includes a method that increases width by a number * Includes another method that increases the length and width (both) by a certain percentage il the user answer is "yes" otherwise don't increase the length and width Class RectangleDemo Create one object » Increase the length by 2 . Increase the width by1 Printout the object * Ask the user if he wants to increase the length and width (both) of the rectangle · Then ask him, by how much percentage. Then printout the new length, width, area, and perimeter Here is an example Rectangle one: length 5 and width 4 Length 7.0 24.9 Do you want to increase the length and wtdth both? Yes ly how much percentaget 28 Length 8.4 Length bet yeu art to intrame the length ind wlett both…" LG IGN OUT

Explanation / Answer

Rectangle.java

public class Rectangle {
//Declaring instance variables
private double length;
private double width;

//Parameterized constructor
public Rectangle(double length, double width) {
super();
this.length = length;
this.width = width;
}

//This method will increases the length based on argument
public void incLength(double num) {
length = length + num;
}

//This method will increases the width based on argument
public void incWidth(double num) {
width = width + num;
}

//This method will increases the length and width based on argument
public void incLenWidthByPercentage(int percent) {
length += length * ((double) percent / 100);
width += width * ((double) percent / 100);
}

//This method will calculates the area
public double area() {
return length * width;
}

//This method will calculates the perimeter
public double perimeter() {
return 2 * (length + width);
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
return "Length=" + length + " Width=" + width + " Area=" + area() + " Perimeter=" + perimeter();
}


}

___________________

Test.java

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

//Declaring variables

int percentage = 0;

String yesOrNo;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Creating an Rectangle class instance

Rectangle r = new Rectangle(5, 6);

//Displaying the Rectangle class info

System.out.println(r);

System.out.println("** After Length increases by 2 and width increases by 1 **");

//Increasing the length by 2

r.incLength(2);

//Increasing the length by 1

r.incWidth(1);

//Displaying the Rectangle class info

System.out.println(r);

System.out.print("Do you want to increase the length and width both ?");

yesOrNo = sc.next();

if (yesOrNo.equalsIgnoreCase("yes")) {

System.out.print("By how much percentage :");

percentage = sc.nextInt();

}

r.incLenWidthByPercentage(percentage);

System.out.println(r);

}

}

______________________

Output:

Length=5.0
Width=6.0
Area=30.0
Perimeter=22.0
** After Length increases by 2 and width increases by 1 **
Length=7.0
Width=7.0
Area=49.0
Perimeter=28.0
Do you want to increase the length and width both ?yes
By how much percentage :20
Length=8.4
Width=8.4
Area=70.56
Perimeter=33.6

_____________Could you rate me well.Plz .Thank You