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
Imagery functions as a coding system to help individuals acquire movement patterns. this describes
denis-greek [22]

Answer:

Imagery can be used to develop qualities in yourself you'd like to have — it's like emotional body-building — and using a technique called “Evocative Imagery” you can cultivate courage, patience, tolerance, humor, concentration, self-confidence or any other quality you'd like to embody.

3 0
3 years ago
Authorization is a set of rights defined for a subject and an object. They are based on the subject’s identity.a. Trueb. False
SVEN [57.7K]

Answer:

True

Explanation:

Authorization is a set of rights defined for a subject and an object. They are based on the subject’s identity.a. Trueb. False

Authorization is a set of rights defined for a subject and an object.

Authorization is a security mechanism used to determine user/client privileges or access levels related to system resources, including computer programs, files, services, data and application features. Authorization is normally preceded by authentication for user identity verification.

4 0
3 years ago
What is computer forensics? Where and how would an IT auditor use thisresource?
riadik2000 [5.3K]

Answer:

Learning how to acquire

Explanation:

4 0
2 years ago
Most network cards contain a port that accepts a(n) ____, which looks similar to a telephone connector but is larger.
Vadim26 [7]
YOUR ANSWER IS -------- It accepts a RJ-45 connector
hope i helped you :).
take care
8 0
4 years ago
If you are logged on to Windows Live Messenger, why would you be unable to engage
Mazyrski [523]

Answer:

I'm not sure i haven't had that problem

Explanation:

7 0
3 years ago
Other questions:
  • How can social media be used in "child-driven" education? What benefits can students around the world gain from social media?
    12·1 answer
  • Which commercial email provider is most closely associated with Apple devices?
    9·1 answer
  • Write a program named Admission for a college’s admissions office. The user enters a numeric high school grade point average (fo
    15·1 answer
  • Um can anyone who is really into science and physics answer this question
    7·1 answer
  • Jake is preparing his resume. He is applying for the position of iOS application developer at a large software company. He wants
    6·1 answer
  • Why would you choose to use Word Art rather than a colored font when creating a Google Slides presentation? There are more fonts
    13·1 answer
  • What is the name of the worm that was written in 1988 that could replicate itself across computers on the internet?
    7·1 answer
  • Will mark brain list
    5·2 answers
  • Giusp minfg gấp vs ạ đáp án thôi nhé
    15·1 answer
  • What are the effects of information systems in the management of corona ?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!