Question: Complete the class Tiles which manages an ArrayList of Rectangles. Each rectangle represents a ceramic floor tile. Tiles contains a constructor and methods to process

Complete the class Tiles which manages an ArrayList of Rectangles. Each rectangle represents a ceramic floor tile. Tiles contains a constructor and methods to process the rectangles

Provide a constructor that initializes the instance variable with an empty array list. Call the instance variable tiles.

Provide methods

add(Rectangle r) which adds a Rectangle object to the Tiles

totalArea() gets the sum of the areas of all the Rectangles in this Tiles

largest() gets the Rectangle with the largest area. If more than one Rectangle has the same ares, return the first.

toString() gets a string representation of the object. This is given to you

a private helper method area(Rectangle r) to get the area of a Rectangle. Use the helper method in the implementation of totalArea() and largest()

Provide Javadoc.

Use the following file:

TilesTester.java

public class TilesTester { public static void main(String[] args) { Tiles rectangles = new Tiles(); rectangles.largest(); //should not throw an exception System.out.println(rectangles.totalArea()); System.out.println("Expected: 0.0"); //add some rectangles rectangles.add(new Rectangle(0, 0, 20, 75)); rectangles.add(new Rectangle(0, 0, 100, 50)); rectangles.add(new Rectangle(0, 0, 80, 40)); rectangles.add(new Rectangle(0, 0, 50, 100)); rectangles.add(new Rectangle(0, 0, 50, 50)); Rectangle max = rectangles.largest(); if (max != null) { System.out.println("Largest: " + max); System.out.println("Expected: Rectangle[x=0,y=0,width=100,height=50]"); } double area = rectangles.totalArea(); System.out.println("total area: " + area); System.out.println("Expected: 17200.0"); } } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!