First task -> Simple Reaction Controller

Imagine that you have been hired by an electronics company to build the software for a simple Reaction-Timer game. The reaction timer has two inputs: a coin-slot that starts the game and a go/stop button that controls it. There is also a display that indicates to the player what he/she should do next. The machine behaves as follows.

1.Initially, the display shows Insert coin, and the machine waits for a player to do so.

2.When the player inserts a coin, the machine displays Press GO! and waits for the player to do so.

3.When the player presses the go/stop button, the machine displays Wait... for a random time between 1.0 and 2.5 seconds.

4.After the random delay expires, the machine displays a time-value that increments every 10 milliseconds, starting at zero. The player must now press the go/stop button as soon as possible the goal of the game is to show fast reactions!

5.If the player presses the go/stop button during the random delay period, i.e. the player tries to guess when the delay will expire, the machine aborts the game and immediately demands another coin.

6.To put it simply, there is no reward for trying to cheat! If the user has not pressed stop after two seconds, the machine will stop automatically no living person could be that slow!

7.Whether the player has pressed the go/stop button within the two seconds waiting time period or not, the machine displays the final timer value for three seconds, then the game is over until another coin is inserted. If the player presses the go/stop button while the measured reaction time is being displayed, the machine immediately displays Insert coin.

Second Task -> Enhanced Reaction Controller

After showing the basic reaction timer machine to potential customers, the marketing department has found that some of them would like to pay more for a deluxe reaction timer that allows multiple games after payment of a single coin. In this machine, when a coin is inserted, the player is allowed to play three games. The operating sequence is very similar to the previous one: insert coin, press the go/stop button, wait random delay, press the go/stop button, then display the time for three seconds. If the machine has not yet completed three games, it then displays Wait.... Subsequently, it waits a (new) random delay and proceeds further as in the first game. After displaying the time for the last game, the machine shows the average time Average= t.tt for five seconds, then the game is over. The enhanced reaction controller should fulfil the following requirements.

1.If after inserting the coin the player fails to press go/stop within ten seconds, the game is over.

2.If the player presses the go/stop button during the waiting period, the game is aborted, and the average value is not displayed. Once again, no reward for cheating!

3.If the player presses the go/stop button while the machine is displaying a reaction-time value, the machine immediately moves on to the next game (or shows the average time) without waiting for the full three seconds of display time.

4.If the player presses the go/stop button while the machine is displaying the average time, the game is immediately over.

You must consist of the following parts:

Your program must consist of the following parts.

A controlling program named ReactionMachine is provided as a base to test your controllers. SimpleReactionController and EnhancedReactionController are the modules which you need to realize. The both components must conform to the interface Controller. This is the main body of the exercises. You are free to write these components in any way you choose, so long as they implement the required interfaces. You must write SimpleReactionController.java that functions like the simple reaction machine described above and EnhancedReactionController.java that behaves like the enhanced multi-game reaction machine.

A Display is a GUI component which you need to write to test your reaction machine. It must conform to the Gui interface. The GUI must have a button labelled Coin inserted and a button labelled Go/Stop. There must be a display region to show the messages of the machine. Times must be displayed with two decimal places. For example, a value of 1.5 seconds must be shown as 1.50. Do not go to too much effort to make your GUI beautiful. We are more concerned here with correct operation of your controllers rather than with your artistic ability! You must write Display.java that implements the necessary GUI functions.

To ensure that we can automatically test your program, you must comply with the following constraints.

Obviously, your program needs a source of timing information. You must obtain this information by implementing the tick method in your controller. The ReactionMachine class guarantees to call this method every 10 milliseconds. Do not use a Java timer, or your program cannot be tested and will fail all the tests.

Your program also needs a source of random numbers. You must obtain your random numbers by calling the getRandom() method in the interface Random. Do not use the Java Random class, or your program will fail all the tests.

Provided java files:

  • Controller.java - Contains an interface specification. Both of your reaction controllers must implement this interface.
  • Gui.java - Contains an interface specification. Your GUI must implement this interface.
  • Random.java - Contains an interface specification for the random number generator.
  • ReactionMachine.java - Contains a simple driver program that will allow you to test your reaction controllers.

Please do not modify the four files above.

Your display and two controllers must work correctly with ReactionMachine.

You will need to add at least three files which three of them must be name as:
SimpleReactionMachine.java
EnhancedReactionMachine.java
Display.java

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.