I just started learning java and i made this small game. here is the code
<import java.util.*; class GuessingGame { public static void main (String []args) { System.out.println("Welcome to the GUESSING GAME"); Scanner scan = new Scanner(System.in); Random rand = new Random(); int guess = 0; int round = 1; int score = 0; String rating=""; while (round <= 10) { int think = rand.nextInt(10)+1; int tries = 1; System.out.println("Round:"+round); System.out.println(); System.out.println("I am thinking of a number from 1 to 10."); System.out.println("You must guess what it is in three tries."); System.out.println("Enter a guess:"); while (tries < 4 ) { guess = scan.nextInt(); if (guess == think) { System.out.println("RIGHT!"); System.out.println("You have won this round."); System.out.println(); score = score + 1; tries = tries + 3; } else { if (guess == think + 1 || guess == think -1) { System.out.println("hot"); } if (guess == think + 2 || guess == think -2) { System.out.println("warm"); } else { System.out.println("cold"); } } tries = tries + 1; } if (guess != think) { System.out.println("Wrong"); System.out.println("The correct number was "+think+"."); System.out.println("You have lost this round"); } round = round + 1; } System.out.println(); System.out.println("Game over!"); System.out.println("You have won "+score+" out of 10 rounds"); if (score <= 7 ){rating = new String ("Amateurs");} if (score == 8 ){rating = new String ("Advanced");} if (score == 9 ){rating = new String ("Professionals");} if (score == 10){rating = new String("Hackers");} System.out.println("Your rating: "+rating); } }>
WHen i compile it in cmd i get this error message:
"guessinggame.java:11: error: cannot access Scanner
Scanner scan = new Scanner(System.in);
^
bad source file: .\Scanner.java
file does not contain class Scanner
Please remove or make sure it appears in the correct subdirectory of the sourcepath.
1 error
"
when i change the import to "import java.util.Scanner; & import java.util.Random;"
it works
WHy does it not work with import java.util.*;??
PLS HELP
(BTW in the game itself are maybe some bugs .. i have not tested it yet... my problem is the java util thing)