Results 1 to 5 of 5
- 12-20-2010, 01:02 PM #1
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
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
- 12-20-2010, 01:14 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
what do you want to accomplish with this line?Java Code:reply = myScanner.findInLine(".").charAt(0);
myScanner.findInLine(".") returns null and null.charAt --> NPE
- 12-20-2010, 01:16 PM #3
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
my intention is to allow me read from my keyboard to (Y or N) to the reply (char)
- 12-20-2010, 01:18 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
:confused:Java Code:reply = myScanner.next().charAt(0);
- 12-20-2010, 01:21 PM #5
Member
- Join Date
- Dec 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Major issues with code - Please help
By aldorfski_17 in forum New To JavaReplies: 3Last Post: 03-29-2010, 04:46 AM -
Issues with updating a canvas in Java
By Sandworm in forum Advanced JavaReplies: 1Last Post: 11-19-2009, 08:58 AM -
Issues with a particular website (Java + forms)
By aromes in forum Advanced JavaReplies: 1Last Post: 04-13-2009, 03:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks