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]
4 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]4 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
What peripheral displays us the image on a computer?​
zhenek [66]

Answer:

The monitor. It can be a CRT,LCD or LED monitors

Explanation:

Hope it helps

6 0
3 years ago
What are some positive impacts technology has on the environment?​
dsp73

Answer:

<u>technology</u> has enabled us to capture useful heat through devices such as solar panels

Explanation:

<h3 />
7 0
3 years ago
Read 2 more answers
A type of technology that can be attached to a tag and used to identify postal packages is a(n) _____.
Rasek [7]

The answer is an RFID tag. Its a device capable of sending short-range signals, therefore making it capable of sending identifying information to a receiver placed close to the tag.

4 0
3 years ago
Read 2 more answers
A sensitivity analysis is another name for what analysis
erastova [34]
<span>another name for what-if analysis   (that what is is called "what-if analysis" </span>
5 0
3 years ago
Someone help me to create book-r-us database design with logical and physical diagram
icang [17]
Hey men, i recommend, not saying that here, do that with a friend or someone but no here aight? <span />
6 0
4 years ago
Other questions:
  • The compare_strings function is supposed to compare just the alphanumeric content of two strings, ignoring upper vs lower case a
    15·1 answer
  • What happened to Henry at the end of Chapter 4 in Bendy and the ink machine?
    9·2 answers
  • What is a common source of connection problems with ethernets?
    9·2 answers
  • What is the purpose of a Program Epic?
    7·2 answers
  • Which of these are correctly formatted python dictionaries? Check all that apply.
    5·2 answers
  • You realize your computer has been infected with malware. The program has been copying itself repeatedly, using up resources. Wh
    10·1 answer
  • How do you check how much space is left in current drive?
    9·1 answer
  • An operating system that allows a single user to work on two or more programs at the same time is what type of OS?
    14·1 answer
  • What is a closed system?​
    7·1 answer
  • True or false. A plug-in card is always required to support pc sound
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!