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
.The __________ comes in handy when I'm using Microsoft Word to type an essay with a specific word number requirement
mihalych1998 [28]

Answer:

character count

Explanation:

The answer is probably character count.

6 0
3 years ago
Simple mail transfer protocol (smtp) uses the well-known port number ______________ by default.
Elden [556K]
I believe it's default is port 587. 
8 0
3 years ago
Read 2 more answers
Erica has always selected large numbers of cells by clicking and dragging her mouse. A shortcut that she could use is to select
labwork [276]
D. enter because if you enter something on a cuputer or laptop your selecting something
5 0
3 years ago
Which words in the sentence make up the adjective phrase? Which word does the adjective phrase modify? The farmer delivers five
jasenka [17]
B....."........."........"...
6 0
3 years ago
Stephen needs to insert a field into a building block that will contain variable data. Which keyboard shortcut can he use to tog
STatiana [176]

Answer:

Alt + F9

Explanation:

The Keyboard shortcut that Stephen can use use to toggle between data and the field codes is Alt + F9. This is in regards to Microsoft Word Fields for both Windows and Mac operating systems. Although ALT + F9 will toggle between these two but for all the fields within the document. If you want to toggle between a single or various fields it would be Shift + F9.

8 0
2 years ago
Other questions:
  • What websites can help you learn about general career treads
    11·1 answer
  • What is UNIX? A program for writing documents Graphical interface Internet browser Operating system
    8·2 answers
  • So I’m doing a PowerPoint of how social media changed my life any ideas what I should right down and what kind of topics should
    11·2 answers
  • You have compiled a new kernel using rpm. when you reboot, the new kernel is not the default selection on the boot menu. you use
    10·1 answer
  • There are a multitude of items that Cyber Security professionals view as attack vectors but none are more prevalent and exploita
    13·1 answer
  • You are an IT technician at your company. The company has two small offices in different cities. The company's head office conta
    5·1 answer
  • Which of the following is NOT one of the Big 3 Google Applications that we discussed?
    9·2 answers
  • Many instruction sets contain the instruction NOOP, meaning no operation, which has no effect on the processor state other than
    14·1 answer
  • What color mode would you use when designing for web & devices?
    9·1 answer
  • What is MVC architecture in relation to developing in web applications? How
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!