java - Trouble with my Restaurant Billing program codes and calculating -
i need regarding computation of user order seems options doesn't have value computed please me how put values in every options , 1 more thing need codes checkbox additional order i'm not in programming , effort can do. need pass project right need quick answer , way problem display 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>(); optionlist.add("1"); optionlist.add("2"); optionlist.add("3"); optionlist.add("4"); 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( null, "please select 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", "pick", joptionpane.yes_no_option, joptionpane.question_message, null, options, optionlist.get(0)); //calculate charge , tip taxamount = charge * tax; totalwithtax = charge + taxamount; tipamount = totalwithtax * tiprate; grandtotal = totalwithtax + tipamount; //display 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); } }
stepping on compiler issues of example.
you need way map options prices, example...
map<string, double> pricelist = new hashmap<>(4); pricelist.put("1", 3d); pricelist.put("2", 4.5d); pricelist.put("3", 5.5d); pricelist.put("4", 7d); then, once user has made there choice, can price selected option using like...
double price = pricelist.get(optionlist.get(value)); the problem display comes down number of issues. apart fact it's possible there might variable width font in use, not columns equal length.
a neat trick use html table display value, example
Comments
Post a Comment