therabidliger
2009-09-16 18:15:05 UTC
Rock Paper Scissors
************************************************************
Player name: Ashley
Player hand: rock
Computer generated value: 0.4408697471080901
Computer hand: paper
The computer wins!
************************************************************
However. I can't get the part that says "The computer wins!/Tie!/etc..." to appear (the last line before ****). And in the line above that no matter what I do the computer always has scissors. It's only supposed to have scissors if the value is greater than or equal to 2/3
Here's my code (I know it kind of sucks this is my first real java project):
public class Project1
{
public static void main(String[] args)
{
String name = (args[0]); //name
String hand = (args[1]); //hand
String chand = " ";
String outcome = " ";
double computer = Math.random(); //random number between 0 and 1
//determines computer hand
if (computer < 1/3) {
chand = "rock";
}
if (computer >= 1/3 && computer < 2/3) {
chand = "paper";
}
if (computer >=2/3) {
chand = "scissors";
}
//determines the winner
if (hand == "rock" && chand == "rock") {
outcome = "Tie!";
}
else if (hand == "rock" && chand == "paper") {
outcome = "The computer wins!";
}
else if (hand == "rock" && chand == "scissors") {
outcome = name + " wins!";
}
else if (hand == "paper" && chand == "rock") {
outcome = name + " wins!";
}
else if (hand == "paper" && chand == "paper") {
outcome = "Tie!";
}
else if (hand == "paper" && chand == "scissors") {
outcome = "The computer wins!";
}
else if (hand == "scissors" && chand == "rock") {
outcome = "The computer wins!";
}
else if (hand == "scissors" && chand == "paper") {
outcome = name + " wins!";
}
else if (hand == "scissors" && chand == "scissors") {
outcome = "Tie!";
}
//output
System.out.println("Rock Paper Scissors");
System.out.println("************************************************************");
System.out.println("Player name: " + name);
System.out.println("Player hand: " + hand);
System.out.println("Computer generated value: " + computer);
System.out.println("Computer hand: " + chand);
System.out.println(outcome);
System.out.println("************************************************************");
}
}