Assignment Scope

1. Update classes due to changing requirements
2. Adding fields to enumerations
3. Add methods to classes to accomplish specific tasks
4. Begin developing the front end, or User Interface, portion of the Euchre game. Based on my professional experience working in the industry I have always had to develop a UI for every application, therefore I translate that experience to students so they can have the same opportunity and be prepared professionally.
5. Typically, there is a one-to-one correlation of back end functionality to front end UI component. Depending upon the design of the application it doesn’t always correlate perfectly, however with Euchre, it works well.

Back-end functionality

AiPlayer.java
Card.java
Game.java
HumanPlayer.java

Front-end UI component

AiPlayerUi.java
CardUi.java
GameUi.java
HumanPlayerUi.java
6. The goal is to develop the front-end components of the game Euchre by creating classes:
a. AiPlayerUi.java
b. GameUi.java
c. HumanPlayerUi.java
7. Students will also begin to learn writing simple ActionListeners or Event Handlers.
8. The UI will be developed in multiple assignments, it is not expected that for Assignment 7 the fully functioning UI is complete.

The image that follows is a prototype of what the UI will look like. It does not have to be an exact match. The rubric will provide guidance and recommendations on how to accomplish this, however feel free to be creative in developing the look and feel of the UI.

Prototype: see image.

Euchre class

1. Add to method main()
Instantiate an instance of class GameUi, passing the reference object of class Game as an argument

Constants class

1. Update enum Face to include the following
a. Nine has the value of 9
b. Ten has the value of 10
c. Jack has the value of 11
d. Queen has the value of 12
e. King has the value of 13
f. Ace has the value of 14
g. Add field value of data type int
h. Add a public getter to return the field value
i. Add a private constructor for enum Face with one parameter of type int; set the field value to the parameter passed in
2. Update enum Suit to include the following
a. Clubs has the rank of 0
b. Diamonds has the rank of 1
c. Hearts has the rank of 2
d. Euchre has the rank of 3
e. Add field rank of data type int
f. Add a public getter to return the field rank
g. Add a private constructor for enum Suit with one parameter of type int; set the field rank to the parameter passed in
h. Example code:
public enum Suit
{
CLUBS (0),
DIAMONDS (1),
HEARTS (2),
SPADES (3);

private int rank;

public int getRank()
{
return rank;
}

private Suit(int rank)
{
this.rank = rank;
}
}

Deck class

Update class to do the following:

a. Add member variable of interface List, specifically only allowing for instances of class Card to be added named cardList
b. Generate the getter/setter for the member variable above
c. Update method shuffleDeck() so that it instantiates the member variable cardList instead of creating a new instance of interface List
d. Write method displayCardList so that is does the following:
a. Return type void
b. Empty parameter list
c. Using an enhanced for loop, loop through the ArrayList of cards and output to the console the card value, face, and color
e. Update the customer constructor to do the following:
a. Calls method shufflDeck again
b. Calls method displayCardList

Game class

Update the class to do the following:

a. Custom constructor Game()
a. Comment out the call to method outputTeams()
b. Add call to method play()
b. Update method setTable() to do the following:
a. Using an enhanced for loop output the names of each Player in the member variable table representing the setup of the players seated at the table
c. Update method dealHand() where the Iterator instance is instantiated, change method call getDeck() in class Deck to method call getCardList()
d. Update method dealOne() to comment out any System.out.println() statements that show what card each player is being dealt if they exist
e. Update method dealTwo() to comment out any System.out.println() statements that show what card each player is being dealt if they exist
f. Create method play() to do the following:
a. Return type of void
b. Empty parameter list
c. Using an enhanced for loop, loop through the players at the table; for each player, call method makeTrump()
g. Update method createTeams
a. Replace the use of the console prompt and class Scanner to get the human player’s name with static method call on class JOptionPane using method showInputDialog passing as an argument the explicit text to prompt the human to enter their name
b. Store the data entered in the input dialog in the variable of type String
h. Add a getter ONLY for member variable of data type class ArrayList that represents the table of players

Player class

Update class to include the following:

a. Add method sortBySuit() to do the following:
a. Instantiate an instance of class ArrayList allowing only for instances of class Card to be elements that represents the sorted hand
b. Loop while the size of member variable hand is greater than zero (0)
i. Create a local variable of type int representing the current position in the ArrayList of member variable hand, initialize it to zero (0)
ii. Instantiate and instance of class Card (reference as firstCard) set equal to the first element in the ArrayList of member variable hand (hint: use the .get() method of class ArrayList)
iii. Using a for loop, starting at index 1, loop through the size of member variable ArrayList hand to do the following:
1. Instantiate an instance of class Card (reference as nextCard) set equal to the next element in the ArrayList hand (i.e. index 1)
2. Write an if statement to sort the cards based on suit and face value ranking with the following logic:
a. If the suit’s rank of the nextCard in the hand is less than the suit’s rank of the firstCard in the hand
b. OR
i. The suit of the nextCard is equal to the suit of the firstCard
ii. AND
iii. The face value of the nextCard in the hand is less than the face value of the firstCard in the hand
1. Update local variable position to equal the for loop’s looping variable
2. Set the firstCard equal to the nextCard
iv. Remove from the member variable hand the card at the current position (hint: on member variable hand call method remove() passing the argument defined in step i.)
v. Add the instance represented as firstCard to the local ArrayList that represents the sorted hand created in step a.
c. Set member variable hand equal to the local ArrayList that represents the sorted hand.

Team class

Update method outputHands() to do the following:
a. Call method sortBySuit() for each player
b. Only call method displayHand() if the player is an instanceof class HumanPlayer

GameUi.java

1. Add member variables of type
a. Game game;
b. JFrame frame;
c. JPanel aiOnePanel;
d. JPanel tablePanel;
e. JPanel aiTwoPanel;
f. JPanel hpPanel;
g. JPanel aiThreePanel;
h. JPanel northPanel;
i. JPanel scorePanel;
j. JMenuBar menuBar;
k. JMenu gameMenu;
l. JMenu helpMenu;
m. JMenuItem newGameMenuItem;
n. JMenuItem exitMenuItem;
o. JMenuItem aboutMenuItem;
p. JMenuItem rulesMenuItem;
2. A custom constructor should be defined that receives a parameter of data type Game class
a. Set member variable of type class Game to the parameter passed in
b. Call method initComponents()
1. A method initComponents() should initialize all the components for the UI and be called from the constructor
a. Set the size of the JFrame
b. Set the default close operation of the JFrame
c. Use default layout manager BorderLayout
d. Set up the JMenuBar
i. JMenu Game should be added to the JMenuBar
ii. JMenuItems New Game and Exit should be added to the JMenu Game
iii. JMenu Help should be added to the JMenuBar
iv. JMenuItems About and Game Rules should be added to the JMenu Help
e. JMenuBar should be set on the JFrame
f. Instantiate member variable aiOnePanel by calling the constructor for class AiPlayerUi, passing as arguments
i. the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii. An integer representing the position of the Player object in the ArrayList
iii. Example: aiOnePanel = new AiPlayerUi(game.getTable().get(Constants.POSITION_2), Constants.POSITION_2);
g. Instantiate member variable aiTwoPanel by calling the constructor for class AiPlayerUi, passing as arguments
i. the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii. An integer representing the position of the Player object in the ArrayList
h. Instantiate member variable aiThreePanel by calling the constructor for class AiPlayerUi, passing as arguments
i. the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
ii. An integer representing the position of the Player object in the ArrayList
i. Instantiate member variable humanPanel by calling the constructor for class HumanPlayerUi, passing as an argument
i. the instance of class Player stored in class Game, member variable table, at the second position of the ArrayList
j. Instantiate member variable northPanel and set the size of the JPanel using the default layout manager FlowLayout
k. Instantiate member variable scorePanel and do the following
i. Set the size of the JPanel
ii. Add a border to the JPanel
l. Resize aiPanelTwo so it will fit in the northPanel with scorePanel
m. Add to northPanel
i. scorePanel
ii. aiTwoPanel
n. Instantiate member variable tablePanel and do the following
i. Set the size of the JPanel
ii. Add a border to the JPanel
o. Add the JPanels to the JFrame in their appropriate locations based on using layout manager BorderLayout
p. Set the visibility of the JFrame (hint: this should ALWAYS be the last step on a UI)
2. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Exit; it should
a. Display a JOptionPane message confirming the user wants to exit using method showConfirmDialog()
b. If yes, exit the application by calling method System.exit() passing the value of 0 as an argument
c. If no, do not exit the application
3. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text About using method showMessageDialog(); it should
a. Display a JOptionPane message informing the user:
a. Application name and version
b. Author
c. Date of development
4. Write an inner class to create an ActionListener that is registered to the JMenuItem with the text Game Rules

AiPlayerUi.java

1. Create class AiPlayerUi so it uses class JPanel as the superclass
2. Add member variables of type:
a. AiPlayer ai;
b. int position;
c. ArrayList cards;
3. A custom constructor should be defined that receives a two parameters; one is data type class Player, the other is data type int
a. Set member variable of type class AiPlayer to the parameter passed in of class Player using an explicit type cast
b. Set member variable position to the parameter of data type int
c. Call method initComponents()
4. Write method initComponents() to initialize all the components for the UI and be called from the constructor
a. Set the size of the JPanel using two methods to ensure the UI isn’t too small
i. setMinimumSize()
ii. setPreferredSize()
b. Instantiate the member variable of data type ArrayList containing elements of class JLabel
c. Using an if statement check if the position is 1 or 3
i. If true, set the layout manager to use BoxLayout so it is aligned on the Y axis
ii. Else, set the layout manager to use BoxLayout so it is aligned on the X axis
d. Call method displayCards()
5. Write method displayCards to do the following
a. Loop through the member variable of data type ArrayList containing elements of class JLabel so there are 5 JLabels
i. Instantiate an instance of class JLabel
ii. Set the size of the JLabel
iii. Add a border to the JLabel
iv. Set the text of the JLabel to explicit text “Card” concatenated with the looping variable
v. Add the JLabel to the ArrayList
vi. Add the JLabel to the JPanel

HumanPlayerUi.java

1. Create class HumanPlayerUi so it uses class JPanel as the superclass
2. Add member variables of type:
a. HumanPlayer human;
b. ArrayList< JButton> cards;
1. A custom constructor should be defined that receives a one parameter, data type class Player
a. Set member variable of type class HumanPlayer to the parameter passed in of class Player using an explicit type cast
b. Call method initComponents()
2. Write method initComponents() to initialize all the components for the UI and be called from the constructor
a. Set the size of the JPanel using two methods to ensure the UI isn’t too small
a. setMinimumSize()
b. setPreferredSize()
c. Instantiate the member variable of data type ArrayList containing elements of class JButton
d. Se the layout manager to use BoxLayout so it is aligned on the X axis
e. Call method displayCards()
3. Write method displayCards to do the following
a. Loop through the member variable of data type ArrayList containing elements of class JButton so there are 5 JButtons
i. Instantiate an instance of class JButton
ii. Set the size of the JButton
iii. Add a border to the JButton
iv. Set the text of the JButton to explicit text “Card” concatenated with the looping variable
v. Add the JButton to the ArrayList
vi. Add the JButton to the JPanel

CardUi.java

Create the class

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.