Jump to content
Sign in to follow this  
alienA2

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

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!"); } }

Edited by alienA2
  • Like 2

Share this post


Link to post
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...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...