CS46A Spring 19

9A

Write a class BookstoreArray which manages Book objects. This is similar to a problem in the last homework but using arrays rather than ArrayLists.

The Book class is provided for you. It has a constructor that takes the title of book and its price as parameters. It has methods to getPrice and getTitle. Copy the Book class into your project. Do not change it in any way. This is the same class you used in the previous lesson.

BookstoreArray has an instance variable Book[]. Call the instance variable books. The constructor takes and array of Book objects as a parameter.

Provide these methods

Provide Javadoc.

For the draft, define the instance variable and implement the constructor. Implement the average method.

9A draft:
9A final:

9B

In this problem you will complete methods in the IntArray class to process integer arrays

The constructor for IntArray take an int array as a parameter.

IntArray has these methods:

For the draft, implement the constructor and the sum method

9B draft:
9B final:

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

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

Provide these method that process the array board

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

For the draft, implement the constructor and the getBoard method

I just realized we have not covered 2d-arrays so I will give you the pseudocode for getBoard. With that and your reading, you should be able to do this. If not, you know where to get help (updated April 10)


        initialize a String board = "";
        for each row (there are 3)
            for each column (there are 3)
                board = board + game[row][column] + " " (add the next character to the string board)
            board = board + "\n" (start a new row)
        }
        return board;
    }

9C draft:
9C final: