9A
Write a class EllipseManagerArray
which manages Ellipse
objects. This is similar to a problem in the last homework but using arrays rather than ArrayLists.
You will use the Ellipse in the Horstmann graphics package.
A EllipseManagerArray
has an instance variable Ellipse[]. Call the instance variable ellipses. The constructor takes and array of Ellipse objects as a parameter.
Provide methods:
public double average
gets the average area of the Ellipses
public void exchange(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 Ellipse largest()
gets the Ellipse
with the largest area. If more than one Ellipse
has the same area, return the first. If the EllipseManagerArray
is empty, return null. The image below shows the formula for the area of an Ellipse
public String toString()
gets a string representation of the array instance variable - provided. (This is why the instance variable must be called ellipses.)Provide Javadoc.
For the draft, define the instance variable and implement the constructor. Implement the average method.
9B
In this problem you will write methods in an IntArray
class to process integer arrays
The constructor for IntArray
takes an int array as a parameter.
IntArray
has these methods:
public int smallest()
gets the smallest integer in the array. If the array is empty, return Integer.MIN_VALUE - the smallest possible integer. This will serve as a flag that there were no elementspublic String negatives()
gets a string containing all the negative numbers in the array separated by a comma (,). There should not be a comma before the first or after the last elementpublic int negativeCount()
gets the number of integers less than or equal to 0For the draft, implement the constructor and the smallest method.
9C
In this problem you will create a class TicTacToeGame
to model a tic-tac-toe game board. The board is represented by a 3 X 3 int array. Rather than X's and O's the players' positions are represented by integer constants
public static final int NONE = 0; //indicates a free space
public static final int PLAYER_1 = 1; //indicates a space marked by player 1
public static final int PLAYER_2 = 2; //indicates a space marked by player 2
You will implement methods to process the array. You will not implement the whole game play.
The constructor takes a 2-d array as a parameter. The array contains integers indicating which spaces are marked by which player. The game may be complete or only partially complete at any one time.
Provide these method that process the array board
public int winner()
returns the winner of the game either NONE, PLAYER_1,or PLAYER_2. If a row, column or diagonal contains three NONE's, return -1. There is a problem. I wrote a bunch of helper methods to simplify the coding. public String getBoard()
returns a string representation of the game board. The string will contain 3 lines each with 3 numbers followed by a space. See the output below.public int[] counts()
returns an int array where array[0] is the number of unused spaces, array[1] is the number of moves made by player 1, and array[2] is the number of moves made by player 2.Output for getBoard
1 2 1
2 1 2
2 0 1
1 1 2
2 2 1
1 2 1
1 0 2
0 1 1
2 2 2
Provide Javadoc
Notice there are two tester programs for the final
For the draft, implement the constructor and declare the constants. Implement the counts method to return an array where all the values are 0. Implement the other methods as stubs. Provide Javadoc