10A
You are to write a class Letters. It has an instance variable of an ArrayList of Pictures. (Be sure to specify a type parameter.) The constructor takes no parameters but must initializes the instance variable.
Provide methods to:
Letters
. Call it add()
. It takes a Picture
as a parametertotalArea()
. It returns an int. If the array list is empty, return 0shortestFirst()
. If two pictures have the same (minimum) height, use the first one. If the array list is empty, return without doing anything. You must use a helper method to find the shortest picture (Try returning the index of the shortest picture). Hint: The ArrayList remove method returns the object that was removed.draw()
. It takes x, y as parametersProvide Javadoc
Add these pictures of letters to your project folder.
For the draft, provide the instance variable and the constructor which initializes the instance variable. Implement the add
method. Implement totalArea
to return the area of the last Picture in Letters. Be sure it will work no matter how many pictures are in the ArrayList. (So you can not assume that there are 4 pictures.)
10B
The class Integer2D has as an instance variable of a a 2-d array of ints. Call the instance variable matrix
. It has a constructor that takes the number of rows and columns as parameters and creates a two dimensional array with the given number of rows and columns, fills it with random ints less that 10, and then assigns it to the instance variable. The row parameter is the first parameter. The constructor is started and provides a Random object that has been create with a seed. Use it to create the random numbers.
You can assume that rows and columns are > 0
Add these methods:
public Integer2D( int rows, int columns
) create the constructor described abovepublic int min()
get the smallest of all the numbers in the array.public boolean contains(int target)
determines if the target is in the 2d array. Return true if it is. Otherwise return falsepublic int[] getDigitCounts()
counts the number of each digit in the array and returns the answer as an array of ints where the number of 0's is at index 0, the number of 1's is at index 1, etc. (note that the numbers in the array are all less than 10) For full credit, be smart about this and do not use a series of if /else if. think of a better way.A toString method is provided.
Provide Javadoc.
The Javadoc for the constructor is incorrect. Replace it with this/** * Constructor for objects of class Integer2D * @param rows the number of rows the Integer2D is to have * @param columns the number of columns the Integer2D is to have */
Also use this for the Javadoc for the provided toString
/** * Gets a string represntation of this object * @return a string represntation of this object */
For the draft, provide the instance variable and complete the constructor. Code the method min
to return the smallest of all the numbers in the last row. Write the Javadoc for what the method will do in the final
10C
Create a class String2D
. Its constructor takes a 2D array of Strings as a parameter. Each element is one word.
Code the constructor and these methods:
public int getCharacterCount()
Gets how many characters are in the array.public int howMany(String letter)
Gets how many times the given letter appears in the array. This is case-sensitivepublic String secondLastRow()
Gets a string containing all the words in the next to the last row separated by an asterisk (*) . Do not place an asterisk after the last word. Only use one loopProvide Javadoc.
For the draft, provide the instance variable and the constructor. Code the getCharacterCount
method