Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

1st Edition

1597496251, 978-1597496254

Students also viewed these Databases questions