Trying to learn java, I have a problem.

In the code I have a problem with this I think

price -= 2.00; (is there some other - that I should be using? because this doesn't work)

its not subtracting the 2.00 it skips it and ends.

this is the error i get when I compile. type Y to have a coupon.

Have a coupon? (Y/N) Exception in thread "main" java.lang.NullPointerException

at TicketPriceWithDiscount.main(TicketPriceWithDiscount.java:14)

import java.util.Scanner;

class TicketPriceWithDiscount {

public static void main(String args[]) {

Scanner myScanner = new Scanner(System.in);

int age;

double price = 0.00;

char reply;

System.out.print("How old are you? ");

age = myScanner.nextInt( );

System.out.print("Have a coupon? (Y/N) ");

reply = myScanner.findInLine(".").charAt(0);

if (age >= 12 && age < 65) {

price = 9.25;

}

if (age < 12 || age >= 65) {

price = 5.25;

}

if (reply == 'Y' || reply == 'y') {

price -= 2.00;

}

if (reply != 'Y' && reply != 'y' &&

reply!='N' && reply!='n') {

System.out.println("Huh?");

}

System.out.print("Please pay $");

System.out.print(price);

System.out.print(". ");

System.out.println("Enjoy the show!");

}

}

[1374 byte] By [CastawayMGa] at [2007-11-26 20:02:38]
# 1
What data are you entering in when the program executes?I just compiled and ran the program fine with different types of data.
lethalwirea at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 2
I type say 24 for age, then Y I have a coupon then I get that error
CastawayMGa at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 3
actually I never get to the part where I get to type Y for coupon
CastawayMGa at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 4
Interesting.Here is what I see.C:\Java>java TicketPriceWithDiscountHow old are you? 24Have a coupon? (Y/N) yPlease pay $7.25. Enjoy the show!
lethalwirea at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 5
ok thanks I don't know why it isn't compiling for me, atleast its not the code, ok thanks.
CastawayMGa at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 6
Well did you edit your code, then recompile? You may not have compiled. So now when you type java TicketPriceWithDiscount it is reading the old class file.
lethalwirea at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 7
yeah I did, I even tried to cut and paste into a new java file and change the class name. same thing, maybe its the compiler, this is the only thing it hasn't been able to run right.. I use JGrasp
CastawayMGa at 2007-7-9 23:01:59 > top of Java-index,Java Essentials,New To Java...
# 8
When you have cousumed the first input by nextInt() call, the scanner content is empty so the return value from your findInLine() call is null. The error message tells that. Scanner is hard to use for beginners. Don' t use it.
hiwaa at 2007-7-9 23:02:00 > top of Java-index,Java Essentials,New To Java...