//****************************************************************************************************
// Project15.java Author: Lewis/Loftus/Cocking
//
// Write an application that plays the rock-paper-scissors game against the computer. When played
// between two people, each person picks one of the three options at the same time and the winner is
// determined. The program should randomly choose one of the three options. Keep playing until the
// user choses to stop, then print the number of user wins, losses, and ties.
//****************************************************************************************************
import java.util.Scanner;
import java.util.Random;
import java.util.*;
public class Project15
{
//----------------------------------------------------------------------------------------------
// Generates random number and asks user to guess.
//----------------------------------------------------------------------------------------------
public static void main (String[] args)
{
Random generator = new Random();
Scanner scan = new Scanner (System.in);
String str, another = "y";
System.out.println("Rock, Paper, or Scissors?");
String choice = scan.nextLine();
int win = 0, tie = 0, lose = 0, winN = 0, loseN = 0, tieN = 0;
final int ROCK = 0, SCISSORS = 1, PAPER = 2;
int comp = generator.nextInt(3);
while (choice.equalsIgnoreCase("rock"))
{
if (comp == 1)
{
System.out.println("Rock beats scissors. You win!");
win++;
}
else if (comp == 2)
{
System.out.println("Paper beats rocks. You lose!");
lose++;
}
else
{
System.out.println("Rock = Rock. Tie!");
tie++;
}
if (comp == 0)
{
System.out.println("The computer's selection was Rock");
}
else if (comp == 1)
{
System.out.println("The computer's selection was Scissors");
}
else
{
System.out.println("The computer's selection was Paper");
}
System.out.println("Play again? (y/n)");
another = scan.nextLine();
}
while (choice.equalsIgnoreCase("paper"))
{
if (comp == 1)
{
System.out.println("Scissors beats paper. You lose!");
lose++;
}
else if (comp == 0)
{
System.out.println("Paper beats rock. You win!");
win++;
}
else
{
System.out.println("Paper = Paper. Tie!");
tie++;
}
if (comp == 0)
{
System.out.println("The computer's selection was Rock");
}
else if (comp == 1)
{
System.out.println("The computer's selection was Scissors");
}
else
{
System.out.println("The computer's selection was Paper");
}
System.out.println("Play again? (y/n)");
another = scan.nextLine();
}
while (choice.equalsIgnoreCase("scissor"))
{
if (comp == 2)
{
System.out.println("Scissors beats paper. You win!");
win++;
}
else if (comp == 0)
{
System.out.println("Rock beats scissors. You lose!");
lose++;
}
else
{
System.out.println("Scissors = scissors. Tie!");
tie++;
}
if (comp == 0)
{
System.out.println("The computer's selection was Rock");
}
else if (comp == 1)
{
System.out.println("The computer's selection was Scissors");
}
else
{
System.out.println("The computer's selection was Paper");
}
System.out.println("Play again? (y/n)");
another = scan.nextLine();
}
if (another.equalsIgnoreCase("n"))
{
winN += win;
loseN += lose;
tieN += tie;
System.out.println("Number of wins: " + winN);
System.out.println("Number of loss: " + loseN);
System.out.println("Number of ties: " + tieN);
System.out.println("Play again? (y/n)");
another = scan.nextLine();
}
}
}
This is what I have so far.
But when I choose to play again, the command doesn't go through.
PLEASE HELP!!!!!