Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: can someone please help me im getting exception

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default can someone please help me im getting exception

    this is all of my code can someone give me some feedback asap.... thanks i appreciate it its in jcreator using java
    import java.util.Scanner;
    import java.util.Formatter;
    import java.text.NumberFormat;
    import java.text.DecimalFormat;
    import java.util.Date;
    import java.text.SimpleDateFormat;
     
     
    public class RodriguezK002PA3
    {
    	private static String customerName;
    	private static Double purchases;
    	private static Double otherCharges;
    	private static Double total;
    	private static Double totalCharges;
    	private static Double totalPackages;
    	private static int packages;
    	private static int moviesOnDemand;
    	private static char toContinue = 'c';
    	private static Scanner input = new Scanner(System.in);
     
    public static void main( String[] args)
    {
    	start();
     
    	System.exit(0);
    }//End main
     
    public static void start()
    {
    	collectData();
    	displayBill();
    	System.exit(0);
     
    }//End start()
     
     
    public static void collectData()
    {
     
    do
    {
     
    	System.out.printf("\n%s","WELCOME TO SA CABLE\n");
     
    	System.out.printf("\n%s","Please enter your name:  ");//ask user to input name
    	customerName = input.nextLine();
     
    do
    {
     
    	System.out.printf("\n%s\n%s","SA CABLE - SUBSCRIPTION PACKAGES\n",
    	"Select your cable subscription package:  \n"
    		+ "\n1. Basic\n"
    		+ "2. Deluxe\n"
    		+ "3. Premium   ");
    	packages = input.nextInt();
     
    	switch(packages)
    	{
     
    		case 1: purchases = 25.00;
    		break;
     
    		case 2: purchases = 50.00;
    		break;
     
    		case 3: purchases = 75.00;
    		break;
     
    		default:
    		System.out.printf("Invalid Selection!");
    		break;
     
     
     
     
    	}//endSwitch
    }while(packages < 1 || packages > 3);
     
    	System.out.printf("\n%s","SA CABLE - MOVIES\n");
     
    	System.out.printf("\nEnter the number of Movies-On-Demand-HD purchases:  ");
    	moviesOnDemand = input.nextInt();
     
     
    	System.out.printf("\nEnter 'Y' to purchase another subscription or 'N' to exit:  ");
    	toContinue = input.next().charAt(0);
    	input.nextLine();
    calcCharges();
     
     
     
    }while(toContinue == 'y'||toContinue == 'Y');
     
     
    return;
    }//end collectData
     
    public static void calcCharges()
    {
     
    otherCharges= moviesOnDemand * 6.00;
     
    totalCharges = totalCharges + otherCharges;
     
    totalPackages = totalPackages + purchases;
     
    total= totalPackages + totalCharges;
     
    return;
    }//end calcCharges
     
    public static void displayBill()
    {
    	Date now = new Date(); //Getting date from operating system
    	SimpleDateFormat formatter = new SimpleDateFormat ("MMMMM dd, yyyy"); //creating formatter to format date in the pattern "MMMMM dd, yyyy"
    	String date = formatter.format(now); //formatting numeric date ocntained in now and storing formatted date into the string variable date
    	NumberFormat money = NumberFormat.getCurrencyInstance();
    	DecimalFormat decimal = new DecimalFormat("#,##0.00");
     
    System.out.printf("\n%s%s","SA CABLE",date,"CHARGES");
    System.out.printf("\n Customer:  ", customerName);
     
    System.out.printf("\n Cable Service:  %10s"
                + "\nMovies-On-Demand-HD:  %4s"
                + "\n\nTOTAL DUE:  %14s",
                money.format(totalPackages), decimal.format(totalCharges), money.format(total));
     
    }//end displayBill
     
    }//endApplication RodriguezK002PA3


  2. #2
    Member
    Join Date
    Mar 2011
    Location
    Earth!
    Posts
    77
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: can someone please help me im getting exception

    You are using "Double", which is a class and can be null. Use "double" instead, it is a primitive type and cannot be null. The class just wraps around the primitive type. Generally it is better to use the primitive type, if I have understood things right . If you on the other hand want to continue to use the class then you must give it a value first, to avoid this kind of problem.

    Also, for future reference, if you get an exception tell us which one it is if you ask for help .

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can someone please help me im getting exception

    The previous reply should cover your exception problems, but to help save you a few key strokes in the future set your toContinue to convert the input to either upper or lowercase characters upon input that way you don't have to put the equal to upper or lower y and or n. (.toUpperCase)

Similar Threads

  1. DAO exception
    By nrao in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 13th, 2010, 11:22 AM
  2. BAd Padding exception
    By Bverly in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 26th, 2010, 03:41 PM
  3. Exception during xml validation
    By vijeta in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 6th, 2010, 01:50 AM
  4. Error of "ClassNotFound Exception"
    By multicoder in forum Exceptions
    Replies: 3
    Last Post: July 1st, 2009, 02:58 PM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM