repl.it
@TMDUBS/

Rock paper scissors game

Java

No description

fork
loading
Files
  • Main.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import java.util.Scanner; 
import java.util.Random; 

class Main{

  public static void main(String[] args){

    Scanner s = new Scanner(System.in);
    
    System.out.println("Welcome to Rock Paper Scissors");
    System.out.println("Pick 1, 2, or 3 for Rock Paper or Scissors, respectively");

    //rock = 1, paper = 2, scissors = 3
    
    int rand = getRandomNumber(1,3);
    int userpick =  s.nextInt();

    if(userpick == 1 && rand == 1){
      System.out.println();
      System.out.println("You tied. Computer: rock");
      System.out.println("Press run to play again");
    }
    else if(userpick == 1 && rand == 2){
      System.out.println();
      System.out.println("You lost. Computer: paper");
      System.out.println("Press run to play again");
    }
    else if(userpick == 1 && rand == 3){
      System.out.println();
      System.out.println("You won! Computer: scissors");
      System.out.println("Press run to play again");
    }
    else if(userpick == 2 && rand == 1){
      System.out.println();
      System.out.println("You won! Computer: rock");
      System.out.println("Press run to play again");
    }
    else if(userpick == 2 && rand == 2){
      System.out.println();
      System.out.println("You tied. Computer: paper");
      System.out.println("Press run to play again");
    }
    else if(userpick == 2 && rand == 3){
      System.out.println();
      System.out.println("You lost. Computer: scissors");
      System.out.println("Press run to play again");
    }
    else if(userpick == 3 && rand == 1){
      System.out.println();
      System.out.println("You lost. Computer: rock");
      System.out.println("Press run to play again");
    }
    else if(userpick == 3 && rand == 2){
      System.out.println();
      System.out.println("You won! Computer: paper");
      System.out.println("Press run to play again");
    }
    else if(userpick == 3 && rand == 3){
      System.out.println();
      System.out.println("You tied. Computer: scissors");
      System.out.println("Press run to play again");
    }
    else {
      System.out.println();
      System.out.println("Why didn't u type 1 2 or 3 read the directions kid");
      System.out.println("Press run to play again");
    }
  }

  private static int getRandomNumber(int start, int end){
    Random rand = new Random();
    return rand.nextInt(end) + start;
  }

}
?