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
Yuliya22 [10]
2 years ago
5

Write a test program that creates two Rectangle objects—one with width 4 and height 40 and the other with width 3.5 and height 3

5.7. Display the width, height, area, and perimeter of each rectangle in this order.
Computers and Technology
1 answer:
BARSIC [14]2 years ago
5 0

Answer:

public class Rectangle {

   private double width;

   private double heigth;

   public Rectangle(double width, double heigth) {

       this.width = width;

       this.heigth = heigth;

   }

   public double getWidth() {

       return width;

   }

   public void setWidth(double width) {

       this.width = width;

   }

   public double getHeigth() {

       return heigth;

   }

   public void setHeigth(double heigth) {

       this.heigth = heigth;

   }

   public double perimeter(double width, double heigth){

       double peri = 2*(width+heigth);

       return peri;

   }

   public double area(double width, double heigth){

       double area = width*heigth;

       return  area;

   }

}

class RectangleTest{

   public static void main(String[] args) {

       //Creating two Rectangle objects

       Rectangle rectangle1 = new Rectangle(4,40);

       Rectangle rectangle2 = new Rectangle(3.5, 35.7);

       //Calling methods on the first Rectangel objects

       System.out.println("The Height of Rectangle 1 is: "+rectangle1.getHeigth());

       System.out.println("The Width of Rectangle 1 is: "+rectangle1.getWidth());

       System.out.println("The Perimeter of Rectangle 1 is: "+rectangle1.perimeter(4,40));

       System.out.println("The Area of Rectangle 1 is: "+rectangle1.area(4,40));

       // Second Rectangle object

       System.out.println("The Height of Rectangle 2 is: "+rectangle2.getHeigth());

       System.out.println("The Width of Rectangle 2 is: "+rectangle2.getWidth());

       System.out.println("The Perimeter of Rectangle 2 is: "+rectangle2.perimeter(4,40));

       System.out.println("The Area of Rectangle 2 is: "+rectangle2.area(4,40));

   }

}

Explanation:

  • Firstly A Rectangle class is created with two fields for width and heigth, a constructor and getters and setters the class also has methods for finding area and perimeters
  • Then a RectangleTest class containing a main method is created and two Rectangle objects are created (Follow teh comments in the code)
  • Methods to get height, width, area and perimeter are called on each rectangle object to print the appropriate value
You might be interested in
When typing lists in a document, you must use single-spacing between each item in the list.
dexar [7]
False False true
Hope it helps
4 0
2 years ago
List any two different between primary memory and secondary memory.​
nikitadnepr [17]

Answer:

Primary memory is directly accessible by Processor/CPU. Secondary memory is not directly accessible by the CPU. ... The memory devices used for primary memory are semiconductor memories. The secondary memory devices are magnetic and optical memories

3 0
3 years ago
Read 2 more answers
What setting in Blender allows you to see the Graph Editor?
Brut [27]

The answer is b It allows you to modify the animation for any properties using F-Curves. The Graph editor has two modes, F-Curve for Actions, and Drivers for Drivers. Both are very similar in function.

3 0
3 years ago
Which of the following is a subsystem of computers providing access to the Internet and offering multimedia and linking capabili
lbvjy [14]
Answer is option C that is w.w.w.
6 0
2 years ago
What considerations should you make when deciding on the size of a table?
Kisachek [45]

Answer:

You should consider the number of cells needed for data, labels, titles, and formulas.

Explanation:

4 0
2 years ago
Other questions:
  • When it comes to saving money, what is a good rule of thumb?
    5·2 answers
  • What two terms below describe a network device with three ports, two of which send and receive all traffic, and the third port m
    6·1 answer
  • Jason wants to open a program with the command prompt window. Which command should he type in the Run dialog box to open the com
    10·1 answer
  • Two or more computers that are linked together are called which of the following
    7·1 answer
  • Availability is an essential part of ________ security, and user behavior analysis and application analysis provide the data nee
    14·1 answer
  • An aerophone is an instrument that causes ________ to vibrate, thus creating sound waves.
    11·2 answers
  • Explain how to utilize the computer in rooms management.​
    13·1 answer
  • The term structure, as it relates to programming, refers to the decisions you make to design your program to best meet its objec
    11·1 answer
  • Program Convert Measurements:
    15·1 answer
  • Without using parentheses, enter a formula in cell F4 that
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!