Compiler problem

Right the idea of this class is to let the user pick a value between 1-10. If the user picks a value between 1-10 this should enable a message being printed out confirming what number the user has picked in words. For example if the user picks the value 1, the message displayed is "One". (i.e. The number 1 as the word is spelt.) If the user picks 2, the message displayed is "Two". etc all the way up to if the user picks the value 10 the message displayed is "Ten". If the user selects a value outside this range the message displayed should be: "Integer not in range 1 to 10 please re-enter".

This is my code for this class.

publicclass displayvalue

{

publicstaticvoid main(String args[])

{

int value = 1-10;

System.out.println("Please enter a value between 1-10");

value = keyboard.readInt();

while ((value < 1) || (value > 11))

{

System.out.println("Integer not in range 1 to 10 please re-enter");

value = Keyboard.readInt();

}

elseif (value=1)

{

System.out.println("One");

}

elseif (value=2)

{

System.out.println("Two");

}

elseif (value=3)

{

System.out.println("Three");

}

elseif (value=4)

{

System.out.println("Four");

}

elseif (value=5)

{

System.out.println("Five");

}

elseif (value=6)

{

System.out.println("Six");

}

elseif (value=7)

{

System.out.println("Seven");

}

elseif (value=8)

{

System.out.println("Eight");

}

elseif (value=9)

{

System.out.println("Nine");

}

elseif (value=10)

{

System.out.println("Ten");

}

}

}

My error message is as follows:

-jGRASP exec: J:\jdk1.3\bin\javac H:\238CS\Worksheet 5\displayvalue.java

H:\238CS\Worksheet 5\displayvalue.java:13: 'else' without 'if'

else if (value=1)

^

H:\238CS\Worksheet 5\displayvalue.java:7: cannot resolve symbol

symbol : variable keyboard

location: class displayvalue

value = keyboard.readInt();

^

H:\238CS\Worksheet 5\displayvalue.java:11: cannot resolve symbol

symbol : variable Keyboard

location: class displayvalue

value = Keyboard.readInt();

^

3 errors

-jGRASP wedge2: exit code for process is 1.

-jGRASP: operation complete.

Can anyone help me please?

[4452 byte] By [unistudent] at [2007-9-30 22:10:45]
# 1

> H:\238CS\Worksheet 5\displayvalue.java:13: 'else'

> without 'if'

> else if (value=1)

Means There is an error at the line 13 of displayvalue.java that you wrote else with if...

> ^

> H:\238CS\Worksheet 5\displayvalue.java:7: cannot

> resolve symbol

> symbol : variable keyboard

> location: class displayvalue

> value = keyboard.readInt();

> ^

> H:\238CS\Worksheet 5\displayvalue.java:11: cannot

> resolve symbol

> symbol : variable Keyboard

> location: class displayvalue

> value = Keyboard.readInt();

> ^

> 3 errors

Have problems in Reading?!

MohdSleem at 2007-7-7 11:23:51 > top of Java-index,Developer Tools,Java Compiler...
# 2

Also, you should consider using a switch statement instead of a whole pile of if...else statements. It makes it easier to read:

switch (value)

{

case 1: System.out.println("One"); break;

case 2: System.out.println("Two"); break;

case 3: System.out.println("Three"); break;

case 4: System.out.println("Four"); break;

case 5: System.out.println("Five"); break;

case 6: System.out.println("Six"); break;

case 7: System.out.println("Seven"); break;

case 8: System.out.println("Eight"); break;

case 9: System.out.println("Nine"); break;

case 10: System.out.println("Ten"); break;

default: System.out.println("Out of range!");

}

scorbett at 2007-7-7 11:23:51 > top of Java-index,Developer Tools,Java Compiler...
# 3

I do not have problems in reading. (I am the same person as unistudent but have had to reregister because this forum doesn't seem to think I exist as unistudent.)

I do however have problems understanding what baffling compiler error messages mean.

e.g. Cannot resolve Symbol error, does not tell you where the problem is. If the error message was something like: "CHECK SPELLING OF WORDS VERY CAREFULLY" or something like "AND ALSO CHECK THE CASE OF LETTERS." Then I would have no problem understanding it.

And when I went here to check out the message: http://mindprod.com/jgloss/compileerrormessages.html#CANNOTRESOLVESYMBOL there was no mention of that particular error message.

I am a beginner at this. I managed to fix the problem in the end but an error message only says what the error is, (and its difficult to understand) it doesn't explain how to fix the error. Its thick.

Thanks scorbett although I didn't read what you had put before fixing the problem.

daveunistudent at 2007-7-7 11:23:51 > top of Java-index,Developer Tools,Java Compiler...
# 4

> H:\238CS\Worksheet 5\displayvalue.java:7: cannot

> resolve symbol

> symbol : variable keyboard

> location: class displayvalue

> value = keyboard.readInt();

This tells that no variable "keyboard" is in scope there and it is also not known as a class whose static method readInt() could be be accessed.

BIJ001 at 2007-7-7 11:23:51 > top of Java-index,Developer Tools,Java Compiler...