8A
Note
There is an error in the code you are given in codecheck for this problem. Just change this code
public DiscoFloor(int x, int y, int width)
//incorrect
to this
public DanceFloor(int x, int y, int width)
//correct
In this problem you will be drawing a dance floor that consists of 7 rows of (filled) colored circles. Each row contains 6 circles. Each circle touches all of its neighbors. Each circle is a random color: either red, green, blue, yellow, orange, and cyan. Complete the class DanceFloor. Use the constants defined for you in the starter code. You must use nested loops. No credit for simply drawing 42 separate circles
For the colors, use the Color constants in the Color class. (Color.RED etc)
The DanceFloor will have this constructor and these methods
public DanceFloor( int x, int y, int w)
where x and y are the coordinates of the upper left-hand corner of the floor, and w is the diameter of a circle. The constructor is provided for you. It also creates a Random object with a seed. Do not change this part of the program. Do not draw in the constructor.public void draw()
draws the dance floor with the 7 rows of 6 filled circlesprivate Color randomColor()
randomly returns a Color object either red, green, blue, yellow, orange, or cyan. Use the Random object created for you in the constructor to determine which to return. You need to use if / else if / else statement structurepublic void setWidth(int w)
sets a new width. Added 3/29/2015.There is trick you can use to determine which color to return. Notice each color has been assigned an integer 0 to 5. You can generate a random number between 0 (inclusive) and 6 (exclusive). If the random number is 0 (RED), return Color.RED. If the random number is 1 (GREEN), return Color.GREEN
You will need to import the graphics package into Bluej.
For the draft, provide a draw method that draws the first circle in each row starting at the given (x, y) coordinates in Color.BLUE. Implement randomColor to always return Color.BLUE.
The draft should look like this.
The final should look like this
8B
Complete the class called ArrayListVeggies. In the main method, do the following
Note: While it is possible to fake this assignment, I strong urge you not to do so. If you do not know how to do something, ask and find out. That way you will know what to do in a situation where the output can not be faked.
For the draft,
8C
Finish the class ArrayListOfStrings
. It contains methods that manipulate an ArrayList of Strings. It has an an instance variable, a ArrayList<String>. Call the instance variable list. The constructor takes no parameters but initializes the instance variable with a new ArrayList<String>()
The class has these methods:
public void add(String text)
adds given string to the array list of stringspublic void lastToUpperCase()
Replaces every element in the list with a version of the String in which the last character is uppercase.public ArrayList<String> longWords()
- Returns a new array list containing only those Strings that are 6 characters long or longer. The original list is not changedpublic void swap(int index1, int index2)
- swaps the element at index1 with the element at index2.If either index i out of bounds return without changing anything.Assume that none of the strings are empty.
I have provided a toString
method to aid testing. (This is why the instance variable must be called list.)
For the draft, provide the constructor and the add()method. Code the other methods as stubs and provide Javadoc.