1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
nasty-shy [4]
3 years ago
14

In this lab, you will create a programmer-defined class and then use it in a Java program. The program should create two Rectang

le objects and find their area and perimeter.InstructionsMake sure the class file named Rectangle.java is open.In the Rectangle class, create two private attributes named length and width. Both length and width should be data type double.Write public set methods to set the values for length and width.Write public get methods to retrieve the values for length and width.Write a public calculateArea() method and a public calculatePerimeter() method to calculate and return the area of the rectangle and the perimeter of the rectangle.Open the file named MyRectangleClassProgram.java.In the MyRectangleClassProgram class, create two Rectangle objects named rectangle1 and rectangle2.Set the length of rectangle1 to 10.0 and the width to 5.0. Set the length of ectangle2 to 7.0 and the width to 3.0.
Computers and Technology
1 answer:
prohojiy [21]3 years ago
7 0

Answer:

class Rectangle{

//private attributes of length and width

private double givenLength;

private double givenWidth;

// constructor to initialize the length and width

public Rectangle(double length, double width){

 givenLength = length;

 givenWidth = width;

}

// setter method to set the givenlength

public void setGivenLength(double length){

 givenLength = length;

}

// setter method to set the givenWidth

public void setGivenWidth(double width){

 givenWidth = width;

}

// getter method to return the givenLength

public double getGivenLength(){

 return givenLength;

}

// getter method to return the givenWidth

public double getGivenWidth(){

 return givenWidth;

}

// method to calculate area of rectangle using A = L * B

public void calculateArea(){

 System.out.println("The area of the rectangle is: " + getGivenLength() * getGivenWidth());

}

// method to calculate perimeter of rectangle using P = 2 * (L + B)

public void calculatePerimeter(){

 System.out.println("The perimeter of the rectangle is: " + 2 * (getGivenLength() + getGivenWidth()));

}

}

public class MyRectangleClassProgram{

public static void main(String args[]){

//rectangle1 object is created

Rectangle rectangle1 = new Rectangle(10.0, 5.0);

//rectangle2 object is created

Rectangle rectangle2 = new Rectangle(7.0, 3.0);

//area for rectangle1 is calculated

rectangle1.calculateArea();

//perimeter for rectangle1 is calculated

rectangle1.calculatePerimeter();

//area for rectangle2 is calculated

rectangle2.calculateArea();

//perimeter for rectangle2 is calculated

rectangle2.calculatePerimeter();

}

}

Explanation:

Two file is attached: Rectangle.java and MyRectangleClassProgram.java

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
You might be interested in
The picture that graphically represents the items you use in Windows is called a/an <br> ___?
jasenka [17]
The picture that graphically represents the items you use in Windows is called an icon. 
8 0
3 years ago
Elise has just edited two photos of her cat and three different photos of her dog. She needs to save all five of these photos in
Lera25 [3.4K]
<span>The best answer is A. cat_1, cat_2, dog_1, dog_2, dog_3. Filenames are preferably short and should state the obvious. They should be unique and distinct, with no any duplicates in any given file within the same folder. The other choices either have duplicates, vague or are way too long to be identified quickly. </span>

<span> </span>

7 0
3 years ago
Read 2 more answers
What is the result when you run the following line of code after a prompt??
qwelly [4]

Answer:

The following output is 14

Explanation:

When you print something, python interprets it and spits it out to the console. In this case, python is just interpreting 3 + 11, which equals 14. Thus, making the answer 14.

hope i helped :D

3 0
2 years ago
The components of hardware include:
zlopas [31]

Answer:

A

Explanation:

Monitor, CPU, Disk Drives, Printer, Keyboard/mouse

5 0
2 years ago
Read 2 more answers
What does &lt;3 mean at the end of a message?
adelina 88 [10]
It is supposed to symbolize a heart, signifying love.
8 0
3 years ago
Other questions:
  • Which is a feature of a strong thesis statement? A) It presents only the facts. B) It is open-ended. C) It answers the central q
    15·1 answer
  • When you hack a website, do you enter in the master code in the html section code data, or the offline/online system?
    14·1 answer
  • PLEASE HELP
    6·1 answer
  • Often used in connection with a business
    6·1 answer
  • Karen took an assessment with 291 questions, and it described her preferred style of working, learning, leading, risk-taking and
    13·1 answer
  • Describe the photograph that David begins discussing what is the contacts for the photograph
    7·1 answer
  • In computers, when the print command is executed, a cable carries this signal from the computer to the printer. In comparing a c
    11·1 answer
  • Given two variables, is Empty of type boolean, indicating whether a class roster is empty or not, and number Of Credits of type
    10·1 answer
  • Write a qbasic program to design any simple software with output ​
    5·1 answer
  • Which statement is true about the energy of electromagnetic radiation?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!