All pastes #439279 Raw Edit

w3rd

public java v1 · immutable
·published 2007-04-14 03:52 UTC
rendered paste body
// javac Rock.java// java Rockimport java.io.*;  public class Rock{ static char ComputerAnswer() throws Exception  {     int Comp_Ans = (int)(3 * Math.random());      char ReVal = 0;   if (Comp_Ans == 0)     ReVal = 'R';   if (Comp_Ans == 1)     ReVal = 'P';   if (Comp_Ans == 2)     ReVal = 'S';   return ReVal;  } // close value returning method ComputerAnswerstatic char HumanAnswer() throws Exception    {        BufferedReader cin;    cin = new BufferedReader(new InputStreamReader(System.in));     char Hum_Ans;  while(true)    {    System.out.print("Choose: [Rock,Paper,Scissors,Quit (i.e. R, P, S, Q)]: ");    Hum_Ans = cin.readLine().charAt(0);    return Hum_Ans;    }  } // close value returning method HumanAnswer static void PrintMethod(char method1, char method2) throws Exception    {    if (method1 == 'P' && method2 == 'R')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Computer wins");   if (method1 == 'P' && method2 == 'S')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Human wins");   if (method1 == 'S' && method2 == 'P')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Computer wins");   if (method1 == 'S' && method2 == 'R')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Human wins");   if (method1 == 'R' && method2 == 'S')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Computer wins");   if (method1 == 'R' && method2 == 'P')    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "Human wins");   if (method1 == method2)    System.out.println("Computer:" + method1 + ", " + "Human:" + method2 + ", " + "tie");  }// closes method PrintMethod  public static void main(String[] argv) throws Exception   {// declare variables        char HumAns;    char CompAns;  // start loop    while (true)      {    // determine computer's choice        CompAns = ComputerAnswer();               // prompt for, and read, the human's choice      HumAns = HumanAnswer();    // if human wants to quit, break out of loop     if (HumAns == 'Q' || HumAns == 'q')           {           System.exit(0);           break;          }    // print results     else        {       PrintMethod(CompAns, HumAns);        }    // end loop      }//while// end program   }//main}//public class