Assignment #6: Arrays
Winter 1999
(To be completed for your lab period February 22-23.)
Objective: To gain experience with the use and manipulation of arrays. Optionally, to try out using graphics.
Write a program that prompts the user for a list of ten unique integers, and then prints the list on a single line in the order they were entered. If the user enters an integer that was previously entered, the program should print ``Duplicate value.'' and prompt for the integer again. An example of the use of the program is given below. (Hint: Use an array to store the integers; check this array for duplicates as each new integer is entered.)
Enter 10 unique integers.
Integer 1: 123
Integer 2: 456
Integer 3: 789
Integer 4: -1
Integer 5: -2
Integer 6: 456
Duplicate value.
Integer 6: -1
Duplicate value.
Integer 6: 2
Integer 7: 8
Integer 8: 456
Duplicate value.
Integer 8: 12
Integer 9: -1
Duplicate value.
Integer 9: 10
Integer 10: 9
123 456 789 -1 -2 2 8 12 10 9
Write a program that adjudicates a game of Tic Tac Toe. The first move belongs to player ``X''. The program first prints an empty board and prompts the user for the ``X'' position. The program then prints the new board and prompts for the ``O'' position. The program alternates between ``X'' and ``O'' until one side wins, or the game is a draw.
An example of the running program is given below. You can modify the details of the interface if you wish. Note that the program is not playing the game; it's acting as a referee between two human players.
Use a 3x3 array to store the board configuration.
Tic Tac Toe.
123
456
789
X moves. Where do you want the X? 1
X23
456
789
O moves. Where do you want the O? 6
X23
45O
789
X moves. Where do you want the X? 2
XX3
45O
789
O moves. Where do you want the O? 9
XX3
45O
78O
X moves. Where do you want the X? 3
XXX
45O
78O
X wins!
If you're ambitious you can optionally extend the program to have the computer play the game, or you can optionally implement the program to use graphics as an applet.
If you choose to implement the game as an applet, be warned that you will need to use programming techniques that have not been covered in class. See the link below to try out the Java applet!!