10A
You are given a class Gallery which models a collection of Pictures. The constructor takes an arraylist of Picture objects
You are to add these methods and constructor and provide javadoc:
public Gallery(ArrayList<Picture> list)
the constructorpublic int getTotalHeight()
Gets the total height of all the pictures public int getCountWiderThan(int width)
Gets the number of pictures that have a width greater than the given valuepublic void shortestFirst()
Put the Picture with the smallest height first. Use a private helper method to find the shortest Picturepublic void draw(int x, int y)
draws the pictures vertically with a gap of 10 pixels between each picture starting at x, yDownload these images and save them in the project folder
For the draft, provide instance variables, the constructor, and the getTotalHeight()
method. Provide Javadoc
10B
Complete the Array2DUtil
class. Array2DUtil
has a constructor that creates a two dimensional array of random ints less that 100 with the given number of rows and columns and assigns it to the instance variable. The Random object is created for you with a seed. Do not change it.
Add these methods
public double average()
Gets the average of all the integers in the array for this Array2DUtilpublic String toString()
returns a string representation of a m x n array with m rows each of which contains the n numbers in the columns of that row, separated by commas. Your method should not use System.out.printlnpublic static double average(int[][] array)
Gets the average of the values in the given 2d array. Notice that you have 2 methods named average: an instance method that works on the instance variable of the class and a static method that works on the parameter passed to it.For the draft, provide instance variable and constructor. Code the instance method average
to return the average of the last column.
10C
Create a class String2DArray
. Its constructor takes a 2D array of Strings as a parameter. The class has methods
public String longestWord()
Gets the longest word in the array. If two words are the same length, return the firstpublic String lastColumn()
Gets a string containing all the words in the last column separated by spacespublic boolean find(String word)
Determines if the array contains the given word. Returns true if it does. otherwise falseFor the draft, implement longestWord().