Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- //program where you can play Rock, Paper, Scissors against a computer
- public class CrocPaperScissors
- {
- public static void main(String[]cocks)
- {
- Scanner scan=new Scanner(System.in);
- boolean playz=true;
- while (playz==true)
- {
- boolean play=true;
- int compCount=0, playCount=0;
- while(play==true&&compCount!=3&&playCount!=3)
- {
- System.out.print("What's your pick?: ");
- String pick=scan.next().substring(0,1).toLowerCase();
- if(pick.equals("r"))
- pick="Rock";
- if(pick.equals("s"))
- pick="Scissors";
- if(pick.equals("p"))
- pick="Paper";
- String computer;
- int choice=(int)(Math.random()*3+1);
- if(choice==1)//Rock, 9 combinations
- {
- computer="Rock";
- System.out.print("The computer picked "+computer+": ");
- if(pick.equals("Scissors"))
- {
- System.out.println("You lose this round!");
- compCount++;
- }
- if(pick.equals("Rock"))
- System.out.println("Tie.");
- if(pick.equals("Paper"))
- {
- System.out.println("You win this round!");
- playCount++;
- }
- }
- if(choice==2)//Scissors, 9 combinations
- {
- computer="Scissors";
- System.out.print("The computer picked "+computer+": ");
- if(pick.equals("Paper"))
- {
- System.out.println("You lose this round!");
- compCount++;
- }
- if(pick.equals("Scissors"))
- System.out.println("Tie.");
- if(pick.equals("Rock"))
- {
- System.out.println("You win this round!");
- playCount++;
- }
- }
- if(choice==3)//Paper, 9 combinations
- {
- computer="Paper";
- System.out.print("The computer picked "+computer+": ");
- if(pick.equals("Rock"))
- {
- System.out.println("You lose this round!");
- compCount++;
- }
- if(pick.equals("Paper"))
- System.out.println("Tie.");
- if(pick.equals("Scissors"))
- {
- System.out.println("You win this round!");
- playCount++;
- }
- }
- }
- if(compCount==3)
- System.out.println("\nComputer Wins!");
- if(playCount==3)
- System.out.println("\nYou Won!");
- System.out.print("\nPlay again?(y/n): ");
- String playAgain=scan.next().substring(0,1).toLowerCase();
- if(playAgain.equals("y"))
- playz=true;
- else
- playz=false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement