Java Reference
In-Depth Information
΢΢Exercise P7.10. Add a method getWinner to the TicTacToe class of
Section 7.6 . It should return "x" or "o" to indicate a winner, or " " if
there is no winner yet. Recall that a winning position has three matching
marks in a row, column, or diagonal.
΢΢΢Exercise P7.11. Write an application that plays tic-tac-toe. Your
program should draw the game board, change players after every
successful move, and pronounce the winner.
΢΢Exercise P7.12. Magic squares. An n¶n matrix that is filled with the
numbers 1, 2, 3, ș, n 2 is a magic square if the sum of the elements in each
row, in each column, and in the two diagonals is the same value. For
example,
16
3
2
13
5
10
11
8
9
6
7
12
4
15
14
1
Write a program that reads in n 2 values from the keyboard and tests
whether they form a magic square when arranged as a square matrix. You
need to test three features:
ȗ Did the user enter n 2 numbers for some n?
ȗ Do each of the numbers 1, 2, ș, n 2 occur exactly once in the user
input?
ȗ When the numbers are put into a square, are the sums of the rows,
columns, and diagonals equal to each other?
If the size of the input is a square, test whether all numbers between 1 and
n 2 are present. Then compute the row, column, and diagonal sums.
Implement a class Square with methods
public void add(int i)
public boolean isMagic()
Search WWH ::




Custom Search