View Single Post
  #1 (permalink)  
Old 07-17-2007, 12:22 AM
Sageinquisitor Sageinquisitor is offline
Member
 
Join Date: Jul 2007
Posts: 10
Sageinquisitor is on a distinguished road
I need help on a practice code for java
Code:
import java.util.Scanner; class Helpful { public static void main(String args[]) { Scanner myScanner = new Scanner(System.in); int age; double price = 0.00; char reply; boolean isKid, isSenior, hasCoupon, hasNoCoupon; System.out.print("How old are you? "); age = myScanner.nextInt(); System.out.print("Have a coupon? (Y/N) "); reply = myScanner.findInLine(".").charAt(0); isKid = age < 12; isSenior = age >= 65; hasCoupon = reply == 'Y' || reply == 'y'; hasNoCoupon = reply == 'N' || reply == 'n'; if (!isKid && !isSenior) { price = 9.25; } if (isKid || isSenior) { price = 5.25; } if (hasCoupon) { price -= 2.00; } if (!hasCoupon && !hasNoCoupon) { System.out.println("Huh?"); } System.out.print("Please pay $"); System.out.print(price); System.out.println("."); System.out.println("Enjoy the movie!"); } }
// below is wat comes up when i hit execute (i type the 34 and hit enter, and the next thing that comes up should make me chose between 'Y' and 'N' but it doesn't)


Quote:
How old are you? 34
Have a coupon? (Y/N) Exception in thread "main" java.lang.NullPointerException
at Helpful.main(Helpful.java:16)

Process completed.

Last edited by JavaBean : 07-17-2007 at 12:31 AM.
Reply With Quote
Sponsored Links