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
A hardware component that keeps data and information when the device is not powered is called a ____ device.
serious [3.7K]

It should be noted that the hardware component that keeps data and information when the device is not powered is called a storage device.

This device can be permanent or temporary storage device.

<h3>What is a storage device?</h3>

Storage device can be regarded as the device that store data.

There are different storage devices for the computer system, they includes;

  • Optical Storage Devices.
  • External HDDs
  • Random Access Memory
  • Flash memory devices.
  • Floppy Disks.

Learn more about storage device at ;

brainly.com/question/21283135

5 0
2 years ago
Questions about the data policy and privacy policy of YT
Ilya [14]

Answer:

I'm confused

Explanation:

7 0
3 years ago
George has a set of software programs installed on his computer to create a digital portfolio. He is not sure what each program
d1i1m1o1n [39]

Explanation:

I thinkcreating and edditing Images matchs to adobePhotoshop

Microsoft word is for adding and Creating text document

Creating andeditingpage layout -Adobe In Design

Desktop Publication-QuarkQuark Xpress

I hope thishelp and If wrong Inform me

Good luck

8 0
3 years ago
Read 2 more answers
What report shows the percentage of traffic that previously visited a website?
lyudmila [28]

Answer:

New vs returning report under the Behaviour shows the percentage of traffic that has visited your site before. The “New vs Returning” report breaks out acquisition, behavior, and conversion goal metrics for new and returning users.

Explanation:

4 0
2 years ago
The CPU (central processing unit), also known as a processor, is considered the brain of the computer. What is the CPU’s functio
MakcuM [25]

It performs the basic arithmetical, logical, and input/output operations of a computer

4 0
3 years ago
Other questions:
  • A cell in a spreadsheet can contain _________?
    12·1 answer
  • How do u determine the voltage across diode
    15·1 answer
  • In the source-code file containing a class's member function definitions, each member function definition must be tied to the cl
    13·1 answer
  • If you specify a user without specifying a hostname, mysql will
    13·1 answer
  • We introduced Sudoku as a CSP to be solved by search over
    13·1 answer
  • Which of the following BEST describes an extranet?
    13·1 answer
  • Which of the following questions will most likely be answered by displaying data on a line graph?
    11·1 answer
  • Which of the following best describes the basic purpose of the internet?
    11·1 answer
  • Which type of programming language translates one line of code at a time and then executes it before moving to the next line?
    5·2 answers
  • Which of the following is true about named ranges?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!