Question: Java: Finish the class Rectangles. It contains methods that manipulate an ArrayList of Rectangles Rectangles has an instance variable ArrayList Call the instance variable list

Java:

Finish the class Rectangles. It contains methods that manipulate an ArrayList of Rectangles

Rectangles has an instance variable ArrayList Call the instance variable list. It has a constructor that takes no parameters but initializes the instance variable to an empty ArrayList

It has methods

public void add(Rectangle r) adds this Rectangle to the ArrayList of Rectangles

public void swap(int index1, int index2) - swaps the element at index1 with the element at index2. If either index is out of bounds, do not changing anything.

public Rectangle largest() gets the Rectangle with the largest area. If more than one Rectangle has the same areas, return the first. If the Rectangles object is empty, return null

public String toString() gets a string representation of the ArrayList - provided. (This is why the instance variable must be called list.)

You will need to import the Udacity graphics package in order to use Rectangle

Provide Javadoc

Note that if you do not implement the methods in order, you may not get the expected results until all the methods are implemented

Please check the answer here: http://www.codecheck.it/files/1707300529eo20qs6aeuc8rtj06pzakdv00

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!