Java Reference
In-Depth Information
//Calculate the cost of the items ordered.
for ( int index = 0; index < listArray.length; index++)
subTotal = subTotal
+ yourChoicesPrices[listArray[index]];
tax = localTax * subTotal;
total = subTotal + tax;
//Display the costs.
bill.append(" JAVA KIOSK A LA CARTE\n\n");
bill.append("--------------- Welcome ----------------\n\n");
for ( int index = 0; index < listArray.length; index++)
{
bill.append(yourChoicesItems[listArray[index]] + "\n");
}
bill.append("\n");
bill.append("SUB TOTAL\t\t$"
+ String.format("%.2f", subTotal) + "\n");
bill.append("TAX \t\t$"
+ String.format("%.2f", tax) + "\n");
bill.append("TOTAL \t\t$"
+ String.format("%.2f", total) + "\n\n");
bill.append("Thank you - Have a Nice Day\n\n");
//Reset list array.
yourChoices.clearSelection();
repaint();
}
public void actionPerformed(ActionEvent event)
{
if (event.getActionCommand().equals("Selection Completed"))
displayBill();
}
public static void main(String[] args)
{
AlaCarte alc = new AlaCarte();
}
}
Sample Run: Figure 12-26 shows a sample run of the program. (To make more
than one selection, click the first selection, hold the Ctrl key, then click the left
mouse button on the other selections. To make contiguous selections, click the first
item, hold the Shift key, then click the last item you want to select.)
Search WWH ::




Custom Search