Professional Documents
Culture Documents
OOP LAB Assg 2 Oct 2016
OOP LAB Assg 2 Oct 2016
Session: July-November,2016
Lab Assignment #2
Q. 1. Write a Java program to model Finite State Machine. The class definition
should have following information
- Number of States
- Current State
- Start and Final State
- State Transition Rules
The class should provide the functions for following-
i) To set the state to be starting state.
ii) Input one character (This method could throw IllegalStateInputException)
iii) One method to get the current state of Finite State Machine.
iv) methods to initialize following information of State Machine
-Number of States
- Start and Final State
- State Transition Rule
Q.2. Write complete Java Application for implementing Minesweeper Game (in
textual mode). Minesweeper game instance should be presented with an object. At
the starting of game user shall provide the size of board (say p X q).
Your program should initialize the Minesweeper board instance with mines at
random locations. Other board location should be filled with number of mines in the
adjacent 8 locations of board (or neighbouring locations).
While playing the game, user shall see p X q characters on screen. For each
unexplored board location, character + is to be displayed. For each explored board
location, 0,1,2,3....8 or * is to be printed on the screen location depending the mine
or neighbouring mine count.
During the play, user should be asked for exploring a board location or
marking a mine location.
Marked Mine location should be displayed with @ symbol on the board
location. After each play interaction, user should be given the count of correctly
marked mines out of total mines.
Q.3. Implement three classes: Storage, Counter and Printer. The Storage class
should store an integer. The Counter class should create a thread that starts
counting from 0(0, 1, 2, 3....) and stores each value in the Storage class. The Printer
class should create a thread that keeps reading the value in the Storage class and
printing it. Write a program that creates an instance of the Storage class and sets up
a Counter and a Printer object to operate on it.
Q.4. Modify the program from the previous exercise to ensure that each number is
printed exactly once, by adding suitable Synchronization.
Now run your simulation for 720 minutes and answer each of the following: