Hello fellow programmers. I just wrote this super simple program and for some reason, JGrasp is having a hard time with my discount variables, saying "they may not have been initialized". Check the code out for yourself. I'm sure I'm just missing something but . . .
Also, the letters in bold are the letters that JGrasp is pointing out.
Thanks in advance!
Also, the letters in bold are the letters that JGrasp is pointing out.
Code:
/* Jonathan Andrew Scott
2/13/07
jscottpass4.java
This program is for a catering service in order to figure up the totals upon which the user
will input. See comment below for more details.
*/
import javax.swing.JOptionPane;
public class jscottpass4
{
// Constants
public static final double BPRICE = 5.50;
public static final double LPRICE = 9.50;
public static final double DPRICE = 16.50;
public static final double BDISCOUNT = .10;
public static final double LDISCOUNT = .15;
public static final double DDISCOUNT = .12;
public static void main(String[] Args)
{
// Variables
double bfastIn, lunchIn, dinnerIn, totalBf, totalL, totalD, beforeTax, totalTax, afterTax;
double bDiscount, lDiscount, dDiscount;
String bfastStr;
String lunchStr;
String dinnerStr;
String totalOutputStr;
bfastStr = JOptionPane.showInputDialog("Enter Number of Breakfast Ordered: ");
bfastIn = Double.parseDouble(bfastStr);
lunchStr = JOptionPane.showInputDialog("Enter Number of Lunches Ordered: ");
lunchIn = Double.parseDouble(lunchStr);
dinnerStr = JOptionPane.showInputDialog("Enter Number of Dinners Ordered: ");
dinnerIn = Double.parseDouble(dinnerStr);
// If statement to check if there is a discount or not
// Breakfast Discount Check
if (bfastIn >= 10)
{
bDiscount = (BPRICE * bfastIn) * BDISCOUNT;
totalBf = (BPRICE * bfastIn) + bDiscount;
}
else
{
totalBf = BPRICE * bfastIn;
}
// Lunch Discount Check
if (lunchIn >= 15)
{
lDiscount = (LPRICE * lunchIn) * LDISCOUNT;
totalL = (LPRICE * lunchIn) + lDiscount;
}
else
{
totalL = LPRICE * lunchIn;
}
// Dinner Discount Check
if (dinnerIn >= 8)
{
dDiscount = (DPRICE * dinnerIn) * DDISCOUNT;
totalD = (DPRICE * dinnerIn) + dDiscount;
}
else
{
totalD = DPRICE * dinnerIn;
}
// Calculations for totals
beforeTax = totalBf + totalL + totalD;
totalTax = beforeTax * .10;
afterTax = beforeTax + totalTax;
// Output Message for All Information
totalOutputStr = "Meal " + "Quantity " + "Cost " + "Discount " + "Cost After Discount\n" +
"Breakfast" + bfastIn + " " + BPRICE + " " + bDiscount + " " + totalBf + "\n" +
"Lunch" + lunchIn + " " + LPRICE + " " + lDiscount + " " + totalL + "\n" +
"Breakfast" + dinnerIn + " " + DPRICE + " " + dDiscount + " " + totalD + "\n";
// Display the dialog for final information.
JOptionPane.showMessageDialog(null, totalOutputStr, "Totaled Information", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Thanks in advance!