I need help regarding with the computation of what the user order it seems that the options doesn't have a value to be computed please help me how to put values in every options and one more thing is i need help with the codes for the checkbox for additional order I'm not really good in programming and this is all the effort i can do. I really need to pass this project right now so i need a quick answer and by the way what is the problem with my display to user?

Help with: Checkbox codes,Computation,JOptionPane Display

package project2;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
public class Project2 {
public static void main(String[] args) {
List<String> optionList = new ArrayList<String>();

        double charge;
        double tax = 0.0675;
        double tipRate = 0.15;
        double totalWithTax;
        double taxAmount;
        double tipAmount;
        double grandTotal;

                //selection of food
                Object[] options = optionList.toArray();
                int value = JOptionPane.showOptionDialog(
                "Please select your Burger:(1 or 2)\n 1. Burger                     $3.00 \n 2. Cheese Burger      $4.50 "
                        + "\n 2. Bacon Burger        $5.50 \n 2. Supreme Burger   $7.00",

        //calculate the charge and the tip
        taxAmount = charge * tax;
        totalWithTax = charge + taxAmount;
        tipAmount = totalWithTax * tipRate;
        grandTotal = totalWithTax + tipAmount;

                //Display it back to the user
                String opt = optionList.get(value);
                JOptionPane.showMessageDialog(null,"You picked " + opt"  \n  meal: $" + charge" \n tax: $" + taxAmount" \n  meal + tax: $" + totalWithTax" \n  total cost(tip included): $" + grandTotal);


3 Years
Discussion Span
Last Post by stultuske

taxAmount = charge * tax;

how do you expect this to work? look at how you declare charge:

double charge;

since charge is a local variable, it doesn't have a default value. and even if it had, that default value would be 0.

so change that line by something like:

double charge = 1.0;

or change that other line by:

taxAmount = value * tax;

or (more likely to be what you want):

use an InputDialog, instead of an OptionDialog. have the value it returns casted to a double, and reference that by charge.

for future reference, it is a lot easier for us to figure out what's going wrong, if you also post the error messages you get.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.