T
the_transcriber
Ok, i've taken everyones suggestions and am going to give more detail
as to what line my error is on.
the line...
reply = myScanner.findInLine(".").charAt(0);
is causing the error...
How old are you? 26
Have a coupon? (Y/N) Exception in thread "main"
java.lang.NullPointerException
at TicketPriceWithDiscount.main(TicketPriceWithDiscount.java:15)
Process completed.
the output let the user anser Y or N for the coupon question! Im very
very new, so speak in the dumbest terms you have! Thanks for
everyone's help.
here is the full code, it is straight out of the Beginning Java for
Dummies book!
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!");
}
}
as to what line my error is on.
the line...
reply = myScanner.findInLine(".").charAt(0);
is causing the error...
How old are you? 26
Have a coupon? (Y/N) Exception in thread "main"
java.lang.NullPointerException
at TicketPriceWithDiscount.main(TicketPriceWithDiscount.java:15)
Process completed.
the output let the user anser Y or N for the coupon question! Im very
very new, so speak in the dumbest terms you have! Thanks for
everyone's help.
here is the full code, it is straight out of the Beginning Java for
Dummies book!
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!");
}
}