Question

Exercise 1: Write a program called FourRectanglePrinter that constructs a Rectangle object, prints its location by...

Exercise 1:
Write a program called FourRectanglePrinter that constructs a Rectangle object,
prints its location by calling System.out.println(box), and then translates and prints
it three more times, so that is the rectangles were drawn, they would form one
large rectangle, as shown at right.
Your program will not produce a drawing. It will simply print the locations of the four rectangles.

Homework Answers

Answer #1

import java.awt.Rectangle;

public class FourRectanglePrinter {

public static void main(String[] args) {

Rectangle box1 = new Rectangle(100, 100, 50, 100);

System.out.println(box1);

Rectangle box2 = new Rectangle(100, 200, 50, 100);

System.out.println(box2);

Rectangle box3 = new Rectangle(150, 100, 50, 100);

System.out.println(box3);

Rectangle box4 = new Rectangle(150, 200, 50, 100);

System.out.println(box4);

}

}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
write a c++ program A class called car (as shown in the class diagram) contains: o...
write a c++ program A class called car (as shown in the class diagram) contains: o Four private variables: carId (int), carType (String), carSpeed (int) and numOfCars (int). numOfCars is a static counter that should be  Incremented whenever a new Car object is created.  Decremented whenever a Car object is destructed. o Two constructors (parametrized and copy constructor) and one destructor. o Getters and setters for the Car type, ID, and speed. And static getter function for numOfCars....
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the...
Part 1: Two Round Conductors Gather all items required for the exercise. Note: If using the lab kit box, remove contents and place in a secure area. Put on your safety goggles. Center the black conductive paper on the top of the box, grid-side up. Place the two metal nuts (conductors) at the (5 cm, 10 cm) and (20 cm, 10 cm) positions on the paper. Secure using two dissection pins for each conductor. See Figure 13. Note: Place the...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary...
Please answer the following Case analysis questions 1-How is New Balance performing compared to its primary rivals? How will the acquisition of Reebok by Adidas impact the structure of the athletic shoe industry? Is this likely to be favorable or unfavorable for New Balance? 2- What issues does New Balance management need to address? 3-What recommendations would you make to New Balance Management? What does New Balance need to do to continue to be successful? Should management continue to invest...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...