8A
Write the class OliverPics
This class encapsulates an ArrayList
of Pictures
in a class and provides methods to process the list.
The constructor takes an ArrayList
of Pictures
as a parameter and uses it to initialize the instance variable.
Provide the methods
public void exchange(int index1, int index2)
Exchanges the pictures at the given indexes. Make sure the indices are valid. If not, do not try to exchangepublic void tallestLast()
Find the tallest picture and move it to the end of the listpublic void draw()
Draws the pictures vertically with a 5 pixel gap between pictures. The upper left hand corner of the first picture is at 0,0. Consider using Picture's
getMaxY
() method.Define and use a local constant for GAP. "Local" means you will define it in the draw method.
Note: There is a second version of the remove method that will remove a specific object.
Here is the code to remove target from the ArrayList called stuff
stuff.remove(target);
Provide Javadoc
For the draft, implement the the constructor and the draw() method. Include Javadoc
The pictures are in this zip, oliver_pics.zip. Download, unzip, and put the pictures in the Bluej project folder
8B
Complete the class PhraseBook
which has an ArrayList of strings as an instance variable and methods to act on the array list. Call the instance variable phrases
Provide a constructor that takes a ArrayList<String> as a parameter and assigns it to the instance variable
Provide methods:
averageLength()
gets the average length of the phrases in the array list or 0 if the ArrayList is emptyshortest()
gets the shortest phrase or null if the array list is empty. If two phrases have the same shortest length, return the firstremove(String target)
removes all occurrence of the given phrasetoString()
returns a string representation of this PhraseBook object (already done for you)Note: There is a second version of the remove method that will remove a specific object.
Here is the code to remove target from the ArrayList
phrases.remove(target);
Provide Javadoc
For the draft, provide the instance variable, the constructor and the averageLength() method. Implement the other methods as stubs (including Javadoc). Remember that the Javadoc for a stub should reflect what the method will do in the final version not what it does in the draft.
Here is the toString
method. Add it to the draft. I intended to include it itn the Codecheck file but did not. (Added Apr 4, 2017)
@Override public String toString() { return phrases.toString(); }
8C
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 TilestotalArea()
gets the sum of the areas of all the Rectangles in this Tileslargest()
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 area(Rectangle r)
to get the area of a Rectangle. Use the helper method in the implementation of totalArea()
and largest()
Provide Javadoc
For the draft, provide the instance variable, the constructor, and the add method. Implement the other methods as stubs
(including Javadoc). Remember that the Javadoc for a stub should reflect what the method will do in the final version not what it does in the draft.