2011-12-19 19:15:46 UTC
import javax.swing.JOptionPane;
class ScissorsRockPaper
{
public static void main(String[] args)
{
int randomNumber=0;
int humanChoice=0;
String humanQuestion;
int human_wins=1;
int comp_wins=1;
JOptionPane.showMessageDialog(null, "Rock - Paper - Scissors\nWhoever wins more than two times is the winner!");
do {
humanQuestion=JOptionPane.showInputDialog(null, "Computer's Move: x\nYour Move:", "Scissor - Rock - Paper", JOptionPane.QUESTION_MESSAGE);
humanChoice=Integer.parseInt(humanQuestion);
randomNumber = (int)(Math.random() * 3);
if (humanChoice==0 && randomNumber==0)
{
JOptionPane.showMessageDialog(null, "Computer is Scissors\nYours is Scissors\nIt is a Tie");
}
else if (humanChoice==1 && randomNumber==1)
{
JOptionPane.showMessageDialog(null, "Computer is Rock\nYours is Rock\nIt is a Tie");
}
else if (humanChoice==2 && randomNumber==2)
{
JOptionPane.showMessageDialog(null, "Computer is Paper\nYours is Paper\nIt is a Tie");
}
else if (humanChoice==1 && randomNumber==2)
{
JOptionPane.showMessageDialog(null, "Computer is Paper\nYours is Rock\nComputer Win and You Lose in round #" + comp_wins);
comp_wins++;
}
else if (humanChoice==2 && randomNumber==0)
{
JOptionPane.showMessageDialog(null, "Computer is Scissors\nYours is Paper\nComputer Win and You Lose in round #" + comp_wins);
comp_wins++;
}
else if (humanChoice==0 && randomNumber==1)
{
JOptionPane.showMessageDialog(null, "Computer is Rock\nYours is Scissors\nComputer Win and You Lose in round #" + comp_wins);
comp_wins++;
}
else if (humanChoice==2 && randomNumber==1)
{
JOptionPane.showMessageDialog(null, "Computer is Rock\nYours is paper\nYou Win and Computer Lose in round #" + human_wins);
human_wins++;
}
else if (humanChoice==0 && randomNumber==2)
{
JOptionPane.showMessageDialog(null, "Computer is Paper\nYours is Scissors\nYou Win and Computer Lose in round #" + human_wins);
human_wins++;
}
else if (humanChoice==1 && randomNumber==0)
{
JOptionPane.showMessageDialog(null, "Computer is Scissors\nYours is Rock\nYou Win and Computer Lose in round #" + human_wins);
human_wins++;
}
else
{
JOptionPane.showMessageDialog(null, "Sorry! No such choice. Please enter (0) for Scissors, (1) for Rock, and (2) for Paper");
}
} while (human_wins<=2 || comp_wins<=2); // end do while loop
/* after the total rounds are over
print out the winner of the game*/
if (humanChoice>randomNumber)
{
JOptionPane.showMessageDialog(null, "Congratulations! You are the final winner after the total of " + human_wins + " rounds");
}
else if (randomNumber>humanChoice)
{
JOptionPane.showMessageDialog(null, "Bad Luck! Computer is the final winner after the total of " + comp_wins + " rounds");
}
} // End Main
} // End Class