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 2 of 2

Thread: Can not figure out my programs error!

  1. #1
    Junior Member
    Join Date
    Feb 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can not figure out my programs error!

    I am trying to create a program where depending on which item you want to rent, you will be asked the number of day you will be renting and then will receive a bill that will show you your total, subtotal, etc... When I try to compile the program I get an error. Can you please help me find the problem!
    import javax.swing.JOptionPane;
    public class RentalDialog {
     
           double TAX = 0.05;
           double bookCOST = 1.50;
           double movieCOST = 2.00;
           double CDCOST = 1.00;
     
       public static void main(String[] args) {
     
           double taxAmount, subtotal, total; 
           int numDays;
     
    int RentalType = Integer.parseInt(JOptionPane.showInputDialog(null, "Which item would you like to rent?:\n1. Book\n2. Movie\n3. CD"));
          double RentalFee = 0;
          switch (RentalType) {
             case 1 : {
             numDays=Integer.parseInt(JOptionPane.showInputDialog("How many days did you want to rent the book at "+bookCOST+ " each:"));
     
                           subtotal = numDays*bookCOST;
     
                           taxAmount = subtotal * TAX ;
     
                           total  = subtotal + taxAmount;
          }
     
             case 2 : {
             numDays=Integer.parseInt(JOptionPane.showInputDialog("How many days did you want to rent the movie at "+movieCOST+ " each:"));
     
                           subtotal = numDays*movieCOST;
     
                           taxAmount = subtotal * TAX ;
     
                           total  = subtotal + taxAmount;
          }
     
             case 3 : {
             numDays=Integer.parseInt(JOptionPane.showInputDialog("How many days did you want to rent the DVD at "+DVDCOST+ " each:"));
     
                           subtotal = numDays*DVDCOST;
     
                           taxAmount = subtotal * TAX ;
     
                           total  = subtotal + taxAmount;
          }
    }
    Last edited by helloworld922; February 15th, 2010 at 08:46 PM.


  2. #2
    Member
    Join Date
    Feb 2010
    Location
    Auburn, AL
    Posts
    31
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: Can not figure out my programs error!

    First of all, you're missing some curly brackets at the end of your program. I think the number is 3. Try adding 1, 2, 3, 4, ... until the error about parsing past the end of the file is resolved.

    Then, you have to make your class variables static if you want to access them inside main. Also, you don't define DVDCOST but use it in the switch statement.

    When I make those changes it compiles fine. Let me know if this helps.
    Let me know what you think of my website:
    http://www.auburn.edu/~carpept
    Comments or suggestions are appreciated!

Similar Threads

  1. can't figure out how to sort an array.
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: February 6th, 2010, 03:07 PM
  2. my programs- Card and CardTest
    By etidd in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 27th, 2010, 08:06 PM
  3. What programs shall i make?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 1
    Last Post: December 27th, 2009, 08:31 AM
  4. Generation of Palindrome number in Java
    By tina.goyal in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2009, 08:49 AM
  5. [SOLVED] Java program to prompt and display the user input number as odd or even
    By napenthia in forum Java Theory & Questions
    Replies: 11
    Last Post: April 22nd, 2009, 01:19 AM