Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package stensax;
  7.  
  8. import java.util.Random;
  9. import java.util.Scanner;
  10.  
  11. public class Stensax {
  12. private static Object user_input;
  13.  
  14.  
  15. public static void main(String[] args) {
  16.  
  17. Random random = new Random();
  18.  
  19.  
  20. Scanner scanner = new Scanner(System.in);
  21.  
  22.  
  23. int userChoice, computerChoice;
  24. String WantToPlay = "Y";
  25. while ( "Y".equals(WantToPlay)){
  26. System.out.println("Välj!(0 = Sten; 1 = Påse; 2 = Sax):");
  27. userChoice = scanner.nextInt();
  28.  
  29.  
  30. if(userChoice < 0 || userChoice > 2)
  31. {
  32. System.out.println("Fel Alternativ. Avslutar Programmet.");
  33.  
  34.  
  35. System.exit(0);
  36. }
  37.  
  38. computerChoice = random.nextInt(3);
  39.  
  40. if(userChoice == computerChoice)
  41. {
  42. if(userChoice == 0)
  43. {
  44. System.out.println("Båda spelarna valde sten!");
  45. }
  46. else if (userChoice == 1)
  47. {
  48. System.out.println("Båda spelarna valde påse!");
  49. }
  50. else
  51. {
  52. System.out.println("Båda spelarna valde sax!");
  53. }
  54.  
  55. System.exit(0);
  56. }
  57.  
  58. if(userChoice == 0)
  59. {
  60. if(computerChoice == 1)
  61. {
  62. System.out.println("Du valde sten; Datorn valde påse");
  63. System.out.println("Datorn vann!");
  64. }
  65. else
  66. {
  67. System.out.println("Du valde sten; Datorn valde sax");
  68. System.out.println("Du vann!");
  69. }
  70. }
  71. else if(userChoice == 1)
  72. {
  73. if(computerChoice == 0)
  74. {
  75. System.out.println("Du valde påse; Datorn valde sten");
  76. System.out.println("Du vann!");
  77. }
  78. else
  79. {
  80. System.out.println("Du valde påse; Datorn valde sax");
  81. System.out.println("Datorn vann!");
  82. }
  83. }
  84. else
  85. {
  86. if(computerChoice == 0)
  87. {
  88. System.out.println("Du valde sax; Datorn valde sten");
  89. System.out.println("Datorn vann!");
  90. }
  91. else
  92. {
  93. System.out.println("Du valde sax; Datorn valde påse");
  94. System.out.println("Du vann!");
  95. }
  96. }
  97.  
  98.  
  99. System.out.print("Continue Y/N?");
  100. }scanner.close();
  101. }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement