Jump to content

error: Have a coupon? (Y/N) Exception in thread "main" java.lang.NullPointerException at NicePrice.main(NicePrice.java:22)


alienA2

Recommended Posts

Please tell me where I am going wrong? ---- I am running my program in the CMD/ Command Prompt (Path linked to BIN for Java in Program Files). Text editor: Notepad++. Error msg:Have a coupon? (Y/N) Exception in thread "main" java.lang.NullPointerException at NicePrice.main(NicePrice.java:22) Code:import java.util.Scanner; class NicePrice{ // list the instructionspublic static void main (String args[]){ // variable declarationsScanner myScanner = new Scanner(System.in);int age;double price = 0.00;char reply;boolean isKid, isSenior, hasCoupon, hasNoCoupon; //prompt the userSystem.out.print("How old are you");age = myScanner.nextInt(); System.out.print("Have a coupon? (Y/N) ");reply = myScanner.findInLine(".").charAt(0); //variable assignmentsisKid = age < 12;isSenior = age >= 65; //variable comparisonshasCoupon = reply == 'Y' || reply == 'y';hasNoCoupon = reply == 'N' || reply == 'n'; // the if statementsif (!isKid && !isSenior){ price = 9.25; } if (isKid || isSenior){ price = 5.25; } if (hasCoupon){ price -= 2.00; } if (!hasCoupon && !hasNoCoupon){System.out.println("WTF? Type a Y/y or an N/n you idiot!");} System.out.print("Hello! Pay R");System.out.print(price);System.out.print(". ");System.out.println("Enjoy the show dude!"); } }

Link to comment
Share on other sites

mkay...me found this on the internet. It looks like it works... reply = myScanner.next().charAt(0); Pls tell me if its wrong...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...