public class remet extends JFrame implements ActionListener
{
static double[] yourChoicesPrices =
{0.85, 0.80, 0.75, 2.75,
2.50, 2.00, 1.50, 3.00,
0.90, 1.00, 2.00,2.55,2.75,.75};
private JList yourChoices;
private JTextArea bill;
double LocalTax = 0.010;
double StateTax = 0.060;
double TotalTax =0;
double subTotal = 0;
double total;
private Container pane;
public remet() throws IOException
{
super("Welcome to The Gourmet");
// File Input
// Display menu on the left pane
FileInputStream inFile = new FileInputStream("C://menu.txt");
DataInputStream menu = new DataInputStream(inFile);
BufferedReader br = new BufferedReader(new InputStreamReader(menu));
String Menu;
ArrayList<String> MenuItems = new ArrayList<String>();
while ((Menu = br.readLine()) != null) {
MenuItems.add(Menu);
}
String[] yourChoicesItems = new String[MenuItems.size()];
yourChoicesItems = MenuItems.toArray(yourChoicesItems);
menu.close();
for (int i=0 ;i <yourChoicesItems.length;i++)
System.out.println();
for (int i=0; i<yourChoicesItems.length -2; i++){
for (int j=yourChoicesItems.length-2; j>=i;j--){
if (yourChoicesItems[j].compareTo(yourChoicesItems[j+1])>0){
String temp =yourChoicesItems [j];
yourChoicesItems[j]=yourChoicesItems[j+1];
yourChoicesItems[j+1]=temp;
}
}
}
//Get the content pane and set its background color
//and layout manager.
pane = getContentPane();
pane.setBackground(new Color(0, 200, 200));
pane.setLayout(new BorderLayout(5, 5));
//Create a label and place it at NORTH. Also
//set the font of this label.
JLabel yourChoicesJLabel = new JLabel("A LA CARTE MENU");
pane.add(yourChoicesJLabel,BorderLayout.NORTH);
yourChoicesJLabel.setFont(new Font("Dialog",Font.BOLD,20));
yourChoices = new JList(yourChoicesItems);
pane.add(new JScrollPane (yourChoices),BorderLayout.WEST);
yourChoices.setFont(new Font("Courier",Font.BOLD,14));
//Create a text area and place it at EAST. Also
//set the font of this text area.
bill = new JTextArea();
JScrollPane Scrollbill = new JScrollPane(bill);
Scrollbill.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
pane.add(Scrollbill,BorderLayout.EAST);
bill.setFont(new Font("Courier",Font.PLAIN,12));
//Create a button and place it in the SOUTH region and
//add an action listener.
JButton button = new JButton("Selection Completed");
pane.add(button,BorderLayout.SOUTH);
button.addActionListener(this);
///
setSize(500, 360);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
//Method to display the order and the total cost.
private void displayBill() throws IOException
{
int[] listArray = yourChoices.getSelectedIndices();
/// This is the second input to get the items
FileInputStream inFile1 = new FileInputStream("" +
"C://menu.txt");
DataInputStream menu = new DataInputStream(inFile1);
BufferedReader br1 = new BufferedReader(new InputStreamReader(menu));
String menuText;
ArrayList<String> menuItems = new ArrayList<String>();
while ((menuText = br1.readLine()) != null) {
menuItems.add(menuText);
}
String[] yourChoicesItems = new String[menuItems.size()];
yourChoicesItems = menuItems.toArray(yourChoicesItems);
menu.close();
//Set the text area to non-edit mode and start
//with an empty string.
bill.setEditable(false);
bill.setText("");
//Calculate the cost of the items ordered.
for (int index = 0; index < listArray.length; index++)
subTotal = subTotal
+ yourChoicesPrices[listArray[index]];
LocalTax = LocalTax * subTotal;
StateTax = StateTax* subTotal;
TotalTax = LocalTax + StateTax;
total = subTotal + LocalTax + StateTax;
//Display the costs.
bill.append(" THE GOURMET\n\n");
bill.append("--------------- Welcome ----------------\n\n");
for (int index = 0; index < listArray.length; index++)
{
bill.append(yourChoicesItems[listArray[index]] + "\n");
bill.append(yourChoicesPrices[listArray[index]] + "\n");
}
bill.append("\n");
bill.append("SUB TOTAL\t\t$"
+ String.format("%.2f", subTotal) + "\n");
bill.append("Local Tax \t\t$"
+ String.format("%.2f", LocalTax) + "\n");
bill.append("State Tax \t\t$"
+ String.format("%.2f", StateTax) + "\n");
bill.append("TOTAL \t\t$"
+ String.format("%.2f", total) + "\n\n");
FileInputStream inFile = new FileInputStream ("c:\\thankyou.txt");
DataInputStream Menu = new DataInputStream(inFile);
BufferedReader br = new BufferedReader(new InputStreamReader (Menu));
String MenuAll;
while ((MenuAll= br.readLine()) != null) {
bill.append(MenuAll+"\n\n" );
}
Menu.close();
//Reset list array.
yourChoices.clearSelection();
repaint();
}
//Make Report for the day
private void Report()
{
PrintWriter outFile = null;
try {
outFile = new
PrintWriter("c:\\Day-End Report.txt");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
outFile.printf("Sales Tax Collected: $%.2f %n" ,TotalTax );
outFile.printf("Total Sales: $%.2f %n" , total );
outFile.close();
}
public void actionPerformed(ActionEvent event)
{
if(event.getActionCommand().equals("Selection Completed"))
try {
displayBill();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Report();
}
public static void main(String[] args) throws IOException
{
remet alc = new remet();
}
}