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
Universal Containers maintains Job information in a Custom Object that contains sensitive information. The only users who should
Elenna [48]

Answer:

C. Grant Access Using Hierarchy sharing setting on the Job Object set to false.

A. "Modify All" permission for Job Object on the Delivery Profile.

E. Organization-Wide Default sharing setting of Private on the Job Object.

Explanation:

In this example, we are dealing with sensitive information. We learn that because of this, the only users who should be able to view and edit job records are the user who owns the record and all users in the delivery profile. In order to protect the information, it is necessary to have an organization-wide default sharing setting of private. After this, we also need the "modify all" permission for job object on the delivery profile and the Grant Access Using Hierarchy sharing setting to be set to false.

7 0
3 years ago
In many supermarkets customers can pay for their shopping using credit cards. (a) Name two items of information stored on the ma
slamgirl [31]

Answer:

Explanation:

Two items on the magnetic strip are, Credit Card info and Balance

Two ways supermarket may check are the PIN pad you are using to pay or their reciept system.

7 0
3 years ago
Theodor is researching computer programming. He thinks that this career has a great employment outlook, so he'd like to learn if
lakkis [162]

Answer:

The capability to program for a longtime and not burn out and to know a few coding languages as well as have the ability to learn new languages quickly.

4 0
3 years ago
Read 2 more answers
How did voyager 1 and voyager 2 made outer space exploration and easier
Anna007 [38]
They made it easier because they mapped out some of the galaxy and hazardous things like Astroid belts or rogue planets
5 0
3 years ago
Hi can someone please help me with this homework please?
notka56 [123]

Answer: How is someone suppose to help those aren't straight questions theres a whole other site you have to go to for that.

4 0
2 years ago
Other questions:
  • A typical self-expelling fire extinguisher empties its contents in
    8·1 answer
  • What are two examples of ways an electronic record may be distributed to others?
    15·1 answer
  • When performing a basic search with Bing, you first type in your search expression and then click a button to begin the search;
    13·1 answer
  • What conclusion did Freud reach when attempting to understand the connection between psychological and physical problems?
    12·1 answer
  • What is the first computer ever made?????
    9·2 answers
  • Why must you be careful when handling a hard drive?
    10·1 answer
  • What is this?
    15·2 answers
  • why does planets orbit the sun? asap i give brainlist i know it on that subject i dont know what else goes with it
    10·1 answer
  • If Anime Characters were real , Who Would Your Anime Wife Would Be (Tell Who And Why)
    10·1 answer
  • Add me on Fortn!te <br> TsarBacon (imma girl)
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!