|
-
January 6th, 2012, 12:47 PM
#1
java.lang.NullPointerException :P
Hi I have just started java lang for some while when i encountered this problem in a .pdf java for dummies . Here is a little programm in which i cant find an error it still compile without error i cant get it run properly .
import java.util.Scanner;
class NicePrice {
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("Do you 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("Ti?");
}
System.out.print("Please pay $");
System.out.print(price);
System.out.print(". ");
System.out.println("Geia Xara!");
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|