while loop error

I can't seem to find the soultion to the following error message:

G:\UOP\POS 406\Java Assignements\Week 3, Assignment 2\MortgageCalcV1.java:53: variable option might not have been initialized

while ((option == 'Y') || (option == 'y'))

^

1 error

Tool completed with exit code 1

The following is my code starting with the while line to the end of while statement:

//While statement to prompt user to continue to use calculator or to quit.

while ((option =='Y') || (option =='y'))

{//begin loop

System.out.print("Enter the amount to be financed: $");

StrPrincpal = dataIn.readLine ();//Places data into the string StrPrincpal

princpal = Double.parseDouble (StrPrincpal);

System.out.println();

System.out.print("Enter the rate: ");

StrIntRate = dataIn.readLine ();//Places data into the string StrPrincpal

IntRate = Double.parseDouble (StrIntRate);

System.out.println();

System.out.print("Enter the term of the loan: ");

StrTerm = dataIn.readLine ();//Places data into the string StrPrincpal

term = Integer.parseInt (StrTerm);

System.out.println();

//Calculation

rate = (IntRate / 100.0) / 12.0;// converts % to decimal format

Calpymt = rate + 1;// calculate interest

term = 30*12;// calculate number of years to number of months

pymt = princpal * (Math.pow(Calpymt, term) * rate)/ (Math.pow (Calpymt, term) -1);// formula to calculate monthly payment

System.out.println("\nMonthly payment will be: " + moneyFormat.format(pymt) +"\n");// outputs monthly payment to screen

System.out.println("Date of report:" + currentDate);

System.out.println("\n");// create a blank line after output

//User response required y or n to refresh the calculator to perform another calculation

System.out.println("Do you wish to calculate another mortgage?\n");

System.out.print("Please Enter Y or N:\t");

System.out.println("\n");

option = (char)System.in.read();

//StrResponse = dataIn.readLine();

//option = Character.parseChar(StrResponse);

//} //close while loop

}//close loop[code]

[/code]

I have defind variable as char option;

Thanks for any assistance you can give me on this issue.

[3296 byte] By [TexasHeata] at [2007-11-27 6:00:31]
# 1
So have you initialized the variable 'option' ?P.S. I suspect you have just done char option;and not char option = 'y';Message was edited by: sabre150
sabre150a at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 2
U must have just declared it but not initialized it, add the following code before the while loopSystem.out.print("Please Enter Y or N:\t");option = (char)System.in.read();
b.m.krajua at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks... gave it a go and it still failed to function.
TexasHeata at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 4
I tried this option and it compiled with errors.
TexasHeata at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 5
Ah well.
DavidKNa at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 6

If you got error message on the compile, then you should read the error messages, understand them, and then fix what's wrong.

Apparently you're not even reading them. You see an error message and say "Darn! It didn't work! Better post to the forums."

Error message are there to help you. Learn to use them.

paulcwa at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 7
> Error message are there to help you. Learn to use> them.Unfortunately, students refuse to do that. When I was tutoring at uni, it would follow a similar pattern.Write codeHit compileGet error messagePut up hand for help
floundera at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 8
lol flounder
lrngjavaa at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 9

This is quite common in novice coding. Especially if it's for a uni assignment ;)

The important thing is that you take the time to understand what the compiler is trying to tell you.

on line 53, the variable "option" is compared to 'Y'. However, if you have only declared "option":-

char option;

as opposed to:-

char option = OPTION_DEFAULT_VALUE;

The Java compiler cannot compile the program if "option" might not have been initialised. If "option" isn't initialised, you'll get an exception when you try to enter the while loop.

Initialise option with a default value before the logic that sets it occurs.

And try to understand what the compiler is telling you.

Iain.Gallowaya at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 10
You must assign an actual variable to 'y' before the while can execute, even if when you first declare the variable, you first declare it as "char y = ' '; ". This should fix your problem and if you receive any others, well then fix the rest of your code
Roqueforta at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 11
Thanks! I'm still struggling with understanding the error messages. As time goes on and the more I code (practice) it will become easyer.... I hope. I appreciate your help and insite.
TexasHeata at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 12
I guess if I understood the error message I would not have asked? I get no pleasure reading comments such as yours. I don't understand why you even took the time to reply if it troubled you so much.
TexasHeata at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 13
Thanks!I really tried for several hours to resolve the error, but at some point you have to give up and ask the pro's.
TexasHeata at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 14
char option = 0;
j_shadinataa at 2007-7-12 16:38:51 > top of Java-index,Java Essentials,New To Java...
# 15

> I guess if I understood the error message I would not

> have asked? I get no pleasure reading comments such

> as yours. I don't understand why you even took the

> time to reply if it troubled you so much.

Sorry I don't see this post as qualifying as "asking":

> I tried this option and it compiled with errors.

paulcwa at 2007-7-21 21:40:19 > top of Java-index,Java Essentials,New To Java...