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 technician is troubleshooting a small network with cable Internet service in which a user is receiving a message in her web br
Irina-Kira [14]

Answer:

True

Explanation:

The technician should first connect a computer directly to the cable modem and attempt to access the Internet, in order to ascertain the message been displayed on the screen. From there, he would know what to do to resolve the issue.

3 0
3 years ago
How many components of a computer? ​
zepelin [54]

Answer:

There are five main hardware components in a computer system: Input, Processing, Storage, Output and Communication devices. Are devices used for entering data or instructions to the central processing unit.

Explanation:

8 0
3 years ago
write a racket recursive function revert which takes a list 'l' as parameter and returns the reverse of the list. do not use bui
polet [3.4K]

have you never read he doit youtrself book?

Explanation:

4 0
3 years ago
Jerry is entering information from the documents that show what customers bought and what they owe. What document is he working
il63 [147K]
The answer would be C. Invoice
4 0
3 years ago
Read 2 more answers
The use of technology to observe a user's actions often without the user's knowledge is known as:
Margaret [11]

Answer:

C

Explanation:

Computer surveillance refers to spying that allows the viewer to gain access of all activity on the given computer.

5 0
3 years ago
Other questions:
  • Which one of these is a mem?
    8·1 answer
  • Need answers for 11&amp;12. Due today. Thanks.
    14·1 answer
  • How do I type the integral symbol?
    7·2 answers
  • When you see this traffic signal is turned on, you may _____________________.
    5·2 answers
  • Unlike oracle, access does not support the decimal data type.​<br><br> a. true<br><br> b. false
    9·1 answer
  • Match the data types to the types of value they are: Currency, Text, Date/time, and Name.
    11·1 answer
  • Under which tab would you look to find the Show in Groups and advanced sort options for messages in Outlook?
    11·2 answers
  • Which system is understood by the computer system​
    7·1 answer
  • Additional rows and columns are inserted into a table using the
    6·1 answer
  • Private notes about individual slides that you leave for yourself or for others who might use the presentation file is called __
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!