Results 1 to 5 of 5
  1. #1
    oenhouse is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Unhappy having issues with this java code...please help out

    Though I am relatively new to Java and I am currently having problems with running this code:

    class AnotherAgeCheck {
    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 you got 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') && (age >= 12 && age < 65)) {
    price -= 2.00;
    }
    System.out.print("Please pay $");
    System.out.print(price);
    System.out.print(".");
    System.out.println ("Enjoy the show!");


    }
    }


    the output reads thus:


    --------------------Configuration: AnotherAgeCheck - JDK version 1.6.0_23 <Default> - <Default>--------------------
    How old are you? 2
    Have you got a coupon? (Y/N)Exception in thread "main" java.lang.NullPointerException
    at AnotherAgeCheck.main(AnotherAgeCheck.java:14)

    Process completed.



    Where did I missed it please

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    Java Code:
    reply = myScanner.findInLine(".").charAt(0);
    what do you want to accomplish with this line?

    myScanner.findInLine(".") returns null and null.charAt --> NPE

  3. #3
    oenhouse is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    my intention is to allow me read from my keyboard to (Y or N) to the reply (char)

  4. #4
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    Java Code:
    reply = myScanner.next().charAt(0);
    :confused:

  5. #5
    oenhouse is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Major issues with code - Please help
    By aldorfski_17 in forum New To Java
    Replies: 3
    Last Post: 03-29-2010, 04:46 AM
  2. Issues with updating a canvas in Java
    By Sandworm in forum Advanced Java
    Replies: 1
    Last Post: 11-19-2009, 08:58 AM
  3. Issues with a particular website (Java + forms)
    By aromes in forum Advanced Java
    Replies: 1
    Last Post: 04-13-2009, 03:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •