Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this assignment. I am a beginner programming with Java, and am

ID: 3761848 • Letter: I

Question

I need help with this assignment. I am a beginner programming with Java, and am not sure how to approach this.

Create a simple memory game using a single-dimension array.

Give the user a choice between difficult levels:

Easy – User gets 20 turns

Medium – User gets 10 turns

Hard – User gets 5 turns

When the user gets a match, they don't lose the turn.
If they don't get a match, they lose a turn. 5 incorrect guesses = game over.
The user guesses two items, these items are revealed to the user. If they match, the cards stay flipped over when presenting the puzzle. Otherwise re-hide the puzzle and ask for a new guess.
The user wins if they match all the items.

Create a game according to the above rules

Your array should use either numbers or letters. (integers might be easier)
You should have at least 10 items to match (so your array should be at least 20 items) If you do more than 10 items, you might want to give the player more turns.
The positions of the 10 items should be randomized every time the game is played. Note: populating the array is one of the big challenges of this assignment
After every guess "clear the screen" before outputting the puzzle again.

for (int n = 0; n < 10; n++)
System.out.println( " " );

Create a game according to the above rules

Your array should use either numbers or letters. (integers might be easier)
You should have at least 10 items to match (so your array should be at least 20 items) If you do more than 10 items, you might want to give the player more turns.
The positions of the 10 items should be randomized every time the game is played. Note: populating the array is one of the big challenges of this assignment
After every guess "clear the screen" before outputting the puzzle again.

Explanation / Answer

public class HangGUI extends JFrame {
JPanel panel, guessLeftPanel, statusPanel, guessPanel, missPanel;
JLabel guessLeftLabel, guessCountLabel, currentStatus, guess, misses;
JTextField statusText, guessText, missesText;


String[] arrayRightWord;
String[] arrayHiddenWord;

String[] getGuess = new String[1];
String missedGuesses = "";


public HangGUI() {


JMenuBar menuBar = new JMenuBar();


JMenu gameMenu = new JMenu("Game");
menuBar.add(gameMenu);

  
JMenuItem readyGame = new JMenuItem("Ready");

JMenuItem exitGame = new JMenuItem("Exitt");
gameMenu.add(readyGame);
gameMenu.add(exitGame);


JMenu choicesMenu = new JMenu("Choices");
menuBar.add(choicesMenu);


ButtonGroup radioButtons = new ButtonGroup();
JRadioButton easy = new JRadioButton("Easy");
JRadioButton medium = new JRadioButton("Medium");
JRadioButton hard = new JRadioButton("Hard");

radioButtons.add(easy);
radioButtons.add(medium);
radioButtons.add(hard);
optionsMenu.add(easy);
optionsMenu.add(medium);
optionsMenu.add(hard);

  
panel = new JPanel(new GridLayout(4, 1, 5, 5));
  
guessLeftPanel = new JPanel(new GridLayout(1, 2, 5, 5));
guessLeftLabel = new JLabel("Guesses left: ");
guessCountLabel = new JLabel();


easy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int difficulty = 10;
guessCountLabel.setText("" + difficulty);
}
});

  
medium.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int difficulty = 7;
guessCountLabel.setText("" + difficulty);
}
});


hard.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int difficulty = 5;
guessCountLabel.setText("" + difficulty);
}
});

  
statusPanel = new JPanel(new GridLayout(1, 2, 0, 0));
currentStatus = new JLabel("Current status: ");
statusText = new JTextField();
statusText.setEditable(false);


guessPanel = new JPanel(new GridLayout(1, 2, 0, 0));
guess = new JLabel("Guess: ");
guessText = new JTextField();
guessText.setDocument(new JTextFieldLimit(1));


missPanel = new JPanel(new GridLayout(1, 2, 0, 0));
misses = new JLabel("Misses: ");

missesText = new JTextField();
missesText.setEditable(false);

add(menuBar);
add(panel);

guessLeftPanel.add(guessLeftLabel);
guessLeftPanel.add(guessCountLabel);
statusPanel.add(currentStatus);
statusPanel.add(statusText);
guessPanel.add(guess);
guessPanel.add(guessText);
missPanel.add(misses);
missPanel.add(missesText);

panel.add(guessLeftPanel);
panel.add(statusPanel);
panel.add(guessPanel);
panel.add(missPanel);
pack();
setVisible(true);


setSize(400, 200);
setTitle("Hangman");
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(menuBar);


  
quitHandler quithandler = new quitHandler();
quitGame.addActionListener(quithandler);

  
startHandler starthandler = new startHandler();
startGame.addActionListener(starthandler);

}

private class quitHandler implements ActionListener {
public void actionPerformed(ActionEvent quitEvent) {
System.exit(0);
}
}

private class startHandler implements ActionListener {
public void actionPerformed(ActionEvent startEvent) {

guessText.getText();
System.out.println("Hej");
}
}