it resets the score each time. I want it to end when the score is five.
import javax.swing.JOptionPane; public class Chapter5RockPaperScissors { public static void main(String[] args) { String computer, person; JOptionPane.showMessageDialog(null, "The first player who reaches 5 points wins"); for(int i = 0; i<5; i++) { computer = ComputerChoice(); person = UserChoice(); JOptionPane.showMessageDialog(null, "The computer's choice is " + computer + "."); Winner(computer, person); } } public static String ComputerChoice() { int computerChoice; String computerChoiceString = ""; computerChoice = (int) (Math.random() * 3); switch (computerChoice) { case 0: { computerChoiceString = "Rock"; break; } case 1: { computerChoiceString = "Paper"; break; } case 2: { computerChoiceString = "Scissiors"; break; } } return computerChoiceString; } public static String UserChoice() { String userChoice; userChoice = JOptionPane.showInputDialog("\nRock\nPaper\nScissiors"); return userChoice; } public static void Winner(String computer, String person) { int scorecomputer = 0; int scoreperson = 0; int scoreperson1; int scorecomputer1; if (computer.equals("Rock")) { switch (person) { case "Rock" -> JOptionPane.showMessageDialog(null, "It is tie"); case "Paper" -> { JOptionPane.showMessageDialog(null, "Paper cover rock. Person is win"); scoreperson1 = scoreperson; scoreperson = scoreperson1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } case "Scissiors" -> { JOptionPane.showMessageDialog(null, "Rock break Scissiors. Computer is win"); scorecomputer1 = scorecomputer; scorecomputer = scorecomputer1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } default -> JOptionPane.showMessageDialog(null, "This is wrong. Please choose rock,paper,scissiors."); } } else if (computer.equals("Paper")) { switch (person) { case "Rock" -> { JOptionPane.showMessageDialog(null, "Paper cover rock. Computer is win"); scorecomputer1 = scorecomputer; scorecomputer = scorecomputer1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } case "Paper" -> JOptionPane.showMessageDialog(null, "It is tie"); case "Scissiors" -> { JOptionPane.showMessageDialog(null, "Scissiors cut paper.Person is win"); scoreperson1 = scoreperson; scoreperson = scoreperson1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } default -> JOptionPane.showMessageDialog(null, "This is wrong. Please choose rock,paper,scissiors."); } } else if (computer.equals("Scissiors")) { switch (person) { case "Rock" -> { JOptionPane.showMessageDialog(null, "Rock break Scissiors. Person is win"); scoreperson1 = scoreperson; scoreperson = scoreperson1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } case "Paper" -> { JOptionPane.showMessageDialog(null, "Scissiors cut paper. Computer is win"); scorecomputer1 = scorecomputer; scorecomputer = scorecomputer1 + 1; JOptionPane.showMessageDialog(null, "Computer Score : "+scorecomputer+"\nPerson Score : "+scoreperson); } case "Scissiors" -> JOptionPane.showMessageDialog(null, "It is tie"); default -> JOptionPane.showMessageDialog(null, "This is wrong. Please choose rock,paper,scissiors."); } } } }