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!
Code :
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;
}
}
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.