Please explain the problem you are having.
Post the complete text of any error messages
or the program's output and show what you want the output to be.
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
Where does the code assign a value to the variable: city? The compiler can not find where that is done, so it gives the error message.
The code asks the user for the name of a city and then reads the users response into a variable.
Should that be where city is given a value?
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
The compiler is telling you what is wrong: the variable city is not assigned a value.
Do you know what an assignment statement is? For example the following statement assigns the value "asdf" to the variable aStr:
aStr = "asdf";
The variable name is to the left of the = and the value assigned is to the right of the =
Look in the code for a statement that starts with: city =
NormR1
Posting Sage
7,742 posts since Jun 2010
Reputation Points: 1,158
Solved Threads: 793
Skill Endorsements: 16
the problem is, every time you enter data and assign a value, for no matter what type of info, you overwrite the value of name, but you don't set the values for the other variables.
for city, this part is what you should change:
// Get the name of a city.
System.out.println ("Enter the name of a city; ");
name = keyboard.nextLine();
stultuske
Industrious Poster
4,490 posts since Jan 2007
Reputation Points: 1,377
Solved Threads: 630
Skill Endorsements: 25
Java variables must be initialize when you use them.
String name = ""; etc etc
They must be initialised before you use their value, but that does not mean that they must be, or should be, initialised when you declare them. Initialising like that is only useful when there is a specific initial or default value for the variable. In the case of this code each variable is assigned a value before it is used, so initialising them in the declarations is a complete waste of time.
In fact initialising in the declaration can be counter-productive because it effectively disables the compiler's checking for correct initialisation. It's far better not to initialise (except for known initial or default values) so the compiler can check your logic.
JamesCherrill
... trying to help
8,668 posts since Apr 2008
Reputation Points: 2,636
Solved Threads: 1,479
Skill Endorsements: 33