//****************************
//Rock.java
//
//Design and implement an application that plays the Rock- Paper- Scissors game against the computer.
//****************************
import cs1.Keyboard;
import java.util.Random;
public class Rock
{
public static void main(String[] args)
{
//User's play: R, P, or S
String personPlay;
//Computer's play: R, P, or S
String computerPlay= '';
//Randomly generated number used to determine
//computer's play
int computerInt;
Random generator = new Random();
//Get player's play
System.out.println ('Play ROCK PAPER SCISSORS!!!');
System.out.println ('R = Rock');
System.out.println ("P = Paper");
System.out.println ('S = Scissors');
System.out.println ('Choose your weapon');
personPlay = Keyboard.readString();
//Make player's play uppercase for ease of comparison
personPlay = personPlay.toUpperCase();
System.out.println ('You chose... '+personPlay+' as your weapon.');
//Generate computer's play (0,1,2)
computerInt = generator.nextInt(3);
//Translate computer's randomly generated play to string
switch (computerInt){
case 0:
computerPlay = 'R';
System.out.println ('Computer has chosen ROCK.');
break;
case 1:
computerPlay = 'P';
System.out.println ('Computer has chosen PAPER.');
break;
case 2:
computerPlay = 'S';
System.out.println ('Computer has chosen SCISSORS.');
break;
default:
System.out.println ('Please re-enter a value between 0-2');
}
//Print computer's play
System.out.println ('The computer has chosen '+computerPlay+'--Prepare for a war!');
}
}
It gives me an error for this line of code: String computerPlay= '';
Also when I imported the cs1 I got an error saying this: static String readString();
This post has been edited by macosxnerd101: 07 November 2010 - 01:51 PM
Reason for edit:: Added code tags.

New Topic/Question
Reply
MultiQuote






|