Simple code. Could you help pls..?
Hi, Could you pls. look at the code. As I run the code the message:
"Do you have a coupon? Exception in thread "main" java.lang.NullPointerException
at TicketPricewithDiscount.main(TicketPricewithDiscou nt.java:15)"
is showing off :confused: . I have copied the code from the book and there it works fine(at least the author writes it works:) . Would appreciate your help. Thanks. (See the full code below).
import java.util.Scanner;
public 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("Do you have a coupon? ");
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 != 'N' && reply!='n'&& reply!= 'Y' && reply!='y'){
System.out.print ("Huh?");
}
System.out.print ("Please pay $ ");
System.out.print(price);
System.out.print(". ");
System.out.println("Enjoyr the show!");
}
}