- What can make this code better?
- And how could I improve this code?
- Oh and what I would love is if someone has a project that is not that challenging but I could learn a lot from it :)
import java.util.Scanner;
public class RockPaperScissors {
final static int ROCK = 1;
final static int PAPER = 2;
final static int SCISSORS = 3;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Start By Entering A number");
int human = input.nextInt();
System.out.println("ROCK IS 1 :: PAPER IS 2 :: SCISSORS 3");
int computerScore = 0, humanScore = 0, computer;
while (human != -1) {
human = input.nextInt();
computer = (int) (Math.random() * 3 + 1);
String h = human == 1 ? "ROCK" : human == 2 ? "PAPER" : "SCISSORS";
String c = computer == 1 ? "ROCK" : computer == 2 ? "PAPER" : "SCISSORS";
if ((human == ROCK && computer == SCISSORS) || (human == PAPER && computer == ROCK) || (human == SCISSORS && computer == PAPER)) {
humanScore++;
System.out.println("Human Won : " + humanScore);
System.out.println("Human Chose " + h + " and Computer Chose " + c);
} else if ((computer == ROCK && human == SCISSORS) || (computer == PAPER && human == ROCK) || (computer == SCISSORS && human == PAPER)) {
computerScore++;
System.out.println("Computer Won : " + computerScore);
System.out.println("Human Chose " + h + " and Computer Chose " + c);
} else if (human == computer) {
System.out.println("HAH YOU BOTH THINK THE SAME! ");
System.out.println("DRAW!");
} else {
System.out.println("Something Went Wrong Try Again:( ");
}
}
System.out.println("\n\nThe Scores Are *DRUM NOISES* ");
for (int i = 0; i < 4; i++) {
System.out.println("------------------------------");
}
System.out.println("Human score : " + humanScore);
System.out.println("Computer score : " + computerScore);
if (humanScore > computerScore) {
System.out.println("Human Race Is saved! We Won!");
} else if (computerScore > humanScore) {
System.out.println("Sadly We Lost. Better Luck Next Time:)");
} else {
System.out.println("Scores are Tied");
}
}
}