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
The FCFS algorithm is particularly troublesome for ____________.
Nina [5.8K]

Answer:

The correct option is (b) multiprogramming systems

The best I can explain: In a time sharing system, each user needs to get a share of the.... at regular intervals.

Explanation:

Don't forget to follow me thanks

8 0
1 year ago
How do u set up a Wi-Fi network on Android ​
AlladinOne [14]

Answer:

These are some way I know

5 0
2 years ago
Design a 16K x 8 memory using the following ICs:
Montano1993 [528]

Answer:

Required memory size is 16k x 8

16k = 24 x 210 = 214

Hence, No. of address lines = 14

No. of data lines = 8

a) Size of IC 1024 x 1

Total number of ICs required = 16k x 8 / 1024 x 1 = 16 x 8 = 128

b) Size of IC 2k x 4

Total number of ICs required = 16k x 8 / 2k x 4 = 8 x 2 = 16

c) Size of IC 1k x 8

Total number of ICs required = 16k x 8 / 1k x 8 = 16 x 1 = 16

Explanation:

For a, 10 address lines from A0 to A9 are used to select any one of the memory location out of 1024 memory locations present in a IC.

For b, 11 address lines from A0 to A10 are used to select any one of the memory location out of 2k=2048 memory locations present in a IC.

For c, 10 address lines from A0 to A9 are used to select any one of the memory location out of 1k=1024 memory locations present in a IC.

3 0
3 years ago
Look at the following code.int x = 7;int *iptr = &amp;x;What will be displayed if you send the expression *iptr to cout ? What h
masha68 [24]

Answer:

The answer to the given question can be given as:

The value of *iptr is 7. and the value of iptr is dynamic.

Explanation:

In the c++ code, it is defined that x is an integer variable that assigns a value which is 7. Then we define a pointer variable that is *iptr. This variable holds an address of the x variable. When we print the value of the iptr variable. if we use the expression *iptr to print value of the pointer variable by cout that is used in c++ for pint values. so the value of the iptr is 7. If we use the expression iptr sent to cout so we show the address of the variable x. In the pointer, it manages the addresses of dynamically allocated so the address of the variable is changed on execution time.

4 0
3 years ago
Yan wants to attract customers specifically searching on Google for Time-B-Gone, his company's unique office-support product. Hi
Alecsey [184]

Answer:

The answer is "Option A".

Explanation:

The dynamic search ads also known as interactive contextual ads, that utilizes google advanced website browsing technologies to dynamically address relevant results requests based on the quality of a chain's website. These ads are beneficial for strategies, and other choices were wrong which can be described as follows:

  • In option B, It helps to upload all the dynamic search ads URLs quickly.
  • In option C, It helps to control computer service.
  • In option D, It increases the network traffic.
6 0
2 years ago
Other questions:
  • Image below please help
    9·1 answer
  • Marissa bought 2 and 1/2 gallons of orange juice to make punch how many quarts of orange juice did Marissa Buy
    15·2 answers
  • Find the word-length 2's complement representation of each of the following decimal numbers:a. 845b. 15000c. 100d. -923
    8·2 answers
  • _____ provides vital protection and maintenance services for system hardware and software, including enterprise computing system
    12·1 answer
  • This is not a feature provided by most GUIS.<br> icons<br> windows<br> forms<br> menus
    14·2 answers
  • For the preceding simple implementation, this execution order would be nonideal for the input matrix; however, applying a loop i
    6·1 answer
  • How can you assess a website for currency?
    14·2 answers
  • Create a PHP page that contains an array of at least 20 movie titles or book titles (your choice). The HTML page should have an
    7·1 answer
  • Your secondary servers have not been able to contact your primary server to synchronize information. How long will the secondary
    12·1 answer
  • What is a disruptive technology? Give an example of an aspect of society that has been impacted by technological change.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!