public class RPS { public static final int Rock = 0; public static final int Paper = 1; public static final int Scissors = 2; private UserInterface ui; private ComputerPlayer cp; private Tally tally; public RPS() { ui = new UserInterface(); cp = new ComputerPlayer(); tally = new Tally("Computer", "User"); } public void play() { boolean goagain = true; int cpchoice, userchoice; String winner; //keep playing do { //get computer choice cpchoice = cp.getNextChoice(); //get user choice userchoice = ui.getNextChoice(); //reveal computer and user choices ui.printChoice(cpchoice, "Computer"); ui.printChoice(userchoice, "User"); //determine the winner winner = determineWinner(cpchoice, userchoice); //update the score tally tally.updateTally(winner); //print the winner and tally ui.printWinner(winner); ui.printTally(tally); //see if the user wants to play again goagain = ui.goAgain(); } while(goagain == true); } private String determineWinner(int cpchoice, int userchoice) { if(cpchoice == userchoice) { return "Tie"; } else if((cpchoice == Scissors && userchoice == Paper) || (cpchoice == Paper && userchoice == Rock) || (cpchoice == Rock && userchoice == Scissors)) { return "Computer"; } else { return "User"; } } }