Problem Description

You are being asked to code a game called the Suitcases and Player Game that is loosely based on the television game known as Deal or No Deal

For the assignment version, there are 3 different suitcases. The suitcases are numbered 1, 2 and 3 and each contains a sum of money. Each time the game is run, at random, one suitcase is chosen to contain $20, the second suitcase to contain $50 and the third suitcase has $100. As one example, suitcase 1 may contain $100, suitcase 2 may have $20 and then suitcase 3 contains $50. Next, the player selects one of the three suitcases. Note that the player does not know what each suitcase contains.

To see if the player wins the game, the value of the players suitcase is compared to the sum of values in the other two suitcases. If the players suitcase contains a value higher than the sum of the other two suitcases, then the player is declared the winner; otherwise the banker is said to win.

There are two versions of the game, one is a DOS window application as described in Part 1 of the specification and the other one is a GUI, a JFrame version as described in Part 2. The classes created in Part 1 will be reused in Part 2 of the assignment. You will need to code several classes to implement this game in Java. As a minimum, it is expected that you will need a class Suitcase representing a suitcase in the game, and a class Player representing the player in the game.

Part 1

Create a COMMAND LINE based application that prints out a welcome message and then asks the user to select a suitcase. After the user types a number, the game runs as shown in the following screen printouts. see image.

Several more examples of the DOS based application are shown below. see image.

Notice, when a number greater than 3 is entered, the program does not stop but assumes the user selected suitcase 3. see image.

Each time the game is run, 3 instances of class Suitcase must be made. One instance has the label 1 with a value of $20 or $50 or $100 randomly placed in it. Another instance has the label 2, with a different value placed in it and the third instance has the label 3 and the final value placed in it.

A basic UML diagram for a class Suitcase representing a suitcase is shown. see image.

After the 3 instances of class Suitcase are created, an instance of class Player is needed. A player knows which instance of class suitcase they have chosen.

A basic UML diagram for a class Player representing a player is shown. Then, a calculation is done to decide if the player or the banker wins the game. see image.

Part 2

Create a Windows GUI application using the following code.

import javax.swing.*;
public class DisplayGame
{
public static void main(String[] args)
{ JFrame w1 = new JFrame("Suitcases and Player Game");
GamePanel myGamePanel = new GamePanel( );
w1.add (myGamePanel) ;
w1.setSize(275, 240);
w1.setVisible(true);
w1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}//end main
}//end class

When the Windows application is running, an instance of class GamePanel displays 3 JButtons, each representing a suitcase, together with a JLabel and a JTextArea.

When the user clicks on any of the displayed JButtons, the Suitcases and Player game runs. Then an appropriate result appears in the JTextArea as shown on the next page. see image.

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.