Task 8 - OOP Assignment 2 - Inheritance + Arrays

Create a class Game with start, stop, restart methods. Define two protected attributes to store player 1 and player 2 names. Methods shall overridden by subclasses of Game class. Subclass shall decide what shall be written in the body of these methods depending on the particular game logic. Create a class TicTacToe, a subclass of Game, that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enum type to represent the value in each cell of the array. The enum’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X in the specified square, and place an O wherever the second player moves. You can get coordinates from each user to place X or 0. Each move must be to an empty square. If user a position that is already occupied, let user to re-enter the position. After each move, print game status and also determine whether the game has been won with winner name and whether its a draw. Get both players names in start.

(optional) If you feel ambitious, modify your program so that the computer makes the moves for one of the players. Also, allow the player to specify whether he or she wants to go first or second.

If you showed anything that you do not understand, you would get 0. You can do less, it would be evaluated accordingly, but if you copied, 0 would be marked with potential unfair means case.
I would check in 1st lab of week staring Apr. 24.


Ref. Dietel Book. Java How to Program. Exercise 8.17


  1. Replies
    1. But you have to do it.

    2. bhai bye USING ur brain

    3. Not much tricky, you just need place X or 0 at position user enters and design different loop iterations to check whether 3 X or 0 are placed in row, column or diagnol.


Post a Comment

Popular posts from this blog

Task 12 - Create Java Program with MySQL Database Connectivity

Java Interfaces and Exception Handling - Practice Problem with Solution

Task 16 - Javafx Program to Create, Retrieve, Update and Delete records with Database