Advertisement
Guest User

Java4BraydenLab9

a guest
Nov 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import java.util.Random;
  2. import java.util.Scanner;
  3.  
  4. public class Lab9 {
  5.  
  6. public static void main(String[] args) {
  7.  
  8. Scanner input = new Scanner(System.in);
  9.  
  10. // ask user to enter a number
  11. System.out.println("Welcome! Enter a number to select scissors, rock or paper.\n" +
  12. "scissors (0), rock (1), paper (2): ");
  13. int choice = input.nextInt();
  14.  
  15. // generate random number
  16.  
  17. Random randomNumber = new Random();
  18. int computerChoice = randomNumber.nextInt((2) + 1);
  19. System.out.println(computerChoice);
  20.  
  21. switch (choice) {
  22. case 0:
  23. switch (computerChoice) {
  24. case 0:
  25. System.out.println("You both chose scissors, it's a tie!");
  26. break;
  27. case 1:
  28. System.out.println("The computer is rock, you are scissors - you lose!");
  29. break;
  30. case 2:
  31. System.out.println("The computer is paper, you are scissors - you win!");
  32. }
  33. break;
  34. case 1:
  35. switch (computerChoice) {
  36. case 0:
  37. System.out.println("The computer is scissors, you are rock - you win!");
  38. break;
  39. case 1:
  40. System.out.println("You both chose rock, it's a tie!");
  41. break;
  42. case 2:
  43. System.out.println("The computer is paper, you are rock - you lose!");
  44. }
  45. break;
  46. case 2:
  47. switch (computerChoice) {
  48. case 0:
  49. System.out.println("The computer is scissors, you are paper - you win!");
  50. break;
  51. case 1:
  52. System.out.println("The computer is rock, you are paper - you win!");
  53. break;
  54. case 2:
  55. System.out.println("You both chose paper, it's a tie!");
  56. }
  57. break;
  58. default:
  59. System.out.println("Enter a valid number");
  60. }
  61.  
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement