2009-04-12 20:46:55 UTC
Why isn't this code working? I copied the code from the book just to try out the program, and I keep getting this error:
Exception in thread "main" java lang. Error: Unresolved compilation problems:
SimpleIO cannot be resolved
//here's the code I'm using:
import jpb.*;
public class lottery {
publis static void main(String[] args) {
SimpleIO.prompt("Enter heads or tails:");
String userInput = SimpleIO.readLine();
if (!userInput.equalsIgnoreCase("heads") &&
!userInput.equalsIgnoreCase("tails")) {
System.out.println("Sorry, didn't enter heads or tails; please try again");
return;
}
double randomNumber = Math.random();
if (userInput.equalsIgnoreCase("heads") &&
randomNumber < 0.5)
System.out.println("YOu win!");
else if (userInput.equalsIgnoreCase("tails") &&
randomNumber >= 0.5)
System.out.println("You win!");
else
System.out.println("Sorry, you lose.");
}
}
//Also, I have a question about import, as in import jpb.* or import javax, etc. Does that importing bring in something from an online resource, or from data that Eclipse Java already has? In other words, do I have to be online for it to work?
Thanks a lot