This program is a java program where the main point is to build a little on-line
ID: 3688553 • Letter: T
Question
This program is a java program where the main point is to build a little on-line food shop. Try to use methods to complete functions.
Program requirements: A food market store invites you to help them build an on-line food order program. Customers can use this program to order food on-line.
The program should include at least 4 functionalities: 1) Add food in order; 2)Remove food from order; 3) Review order; 4) Check out the order. You can use a menu as a UI (user interface).
Assume there are 4 types of food: Hamburger ($8), Lemonade ($3), Chicken Wing ($1), and Pizza ($6). Customer can order any kinds of food, and any amount of them.
Scenario 1: Costumer A ordered 3 Hamburger and 2 Lemonade, and then removed 1 Hamburger and ordered 5 Chicken wings. Check them out finally.
Scenario 2: Costumer B ordered 10 chicken wings and 1 pizza, and then he reviewed his order,
and then add 1 more pizza. Check them out finally.
i) In the add food in order module, your program may need a menu too to show all sorts of food and their price. The input should be food ID and amount. Your program should record the information to calculate the total fee.
ii) In the review order module, all kinds of food information the customer ordered will be shown. The information includes unit price, amount, subtotal fee, and total fee.
iii) In the remove food from order module, customer can remove food from order. The input should be the food ID and amount. Your program should record the changed information.
iv) In the checking out module, the program will print out the bill (review information and tax fee and checkout fee). Checkout fee= total + tax. Taxfee = total * 7.77%. Taxrate: 7.77%. In addition, you can add other modules, such as customer login module, food delivery module, etc.
Output looks like the following:
This output is just an example. You may make it better.
Hint: You may need to declare several global variables to contain customer's order information, like the quantity of any food, the prices, and so on, so that your methods can use them directly. Or the methods pass the data to each other by parameters and returning data.
Hint: You may need the following methods to be created: functionMenu(), foodMenu(), add FoodToOrder(), removeFoodFromOrder(), reviewOrder(), and checkout().
Hint:In the main method, you may need a
sentinel control led loop to control the whole process.
Hint: Think about the situations that the customers mayinput a wrong character/number.
Explanation / Answer
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class Cancellation extends Connect implements ActionListener,ItemListener
{
JFrame f;
JLabel l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11;
JTextField t1,t2,t3,t4,t5,t6,t7;
JButton b1,b2;
Choice h;
List li;
PreparedStatement ps;
ResultSet rs;
Statement st;
Cancellation()
{
f=new JFrame("Cancellation");
f.getContentPane().setLayout(null);
f.getContentPane().setBackground(Color.green);
l1=new JLabel("PNR No");
l1.setBounds(130,50,50,30);
l2=new JLabel("Train No");
l2.setBounds(50,90,100,30);
l3=new JLabel("Train Name");
l3.setBounds(50,120,100,30);
l4=new JLabel("Class");
l4.setBounds(50,150,100,30);
l5=new JLabel("Date of Journey");
l5.setBounds(50,180,100,30);
l6=new JLabel("From");
l6.setBounds(50,210,100,30);
l7=new JLabel("To");
l7.setBounds(250,210,50,30);
l8=new JLabel("Boarding at");
l8.setBounds(50,240,100,30);
l9=new JLabel("Name of Passenger");
l9.setBounds(90,290,120,30);
l10=new JLabel("Age");
l10.setBounds(240,290,30,30);
l11=new JLabel("Gender");
l11.setBounds(290,290,100,30);
b1=new JButton("Ok");
b1.setBackground(Color.yellow);
b1.addActionListener(this);
b1.setBounds(50,480,100,30);
b2=new JButton("Back");
b2.setBackground(Color.yellow);
b2.addActionListener(this);
b2.setBounds(200,480,100,30);
b1.setMnemonic('O');
b2.setMnemonic('B');
h=new Choice();
h.setBounds(230,50,140,30);
h.addItemListener(this);
t1=new JTextField(10);
t1.addActionListener(this);
t1.setBounds(150,90,100,30);
t2=new JTextField(10);
t2.addActionListener(this);
t2.setBounds(150,120,100,30);
t3=new JTextField(10);
t3.addActionListener(this);
t3.setBounds(150,150,100,30);
t4=new JTextField(10);
t4.addActionListener(this);
t4.setBounds(150,180,100,30);
t5=new JTextField(10);
t5.addActionListener(this);
t5.setBounds(150,210,100,30);
t6=new JTextField(10);
t6.addActionListener(this);
t6.setBounds(300,210,100,30);
t7=new JTextField(10);
t7.addActionListener(this);
t7.setBounds(150,240,100,30);
li=new List(5,true);
li.setBounds(80,320,320,100);
f.getContentPane().add(l1);
f.getContentPane().add(l2);
f.getContentPane().add(l3);
f.getContentPane().add(l4);
f.getContentPane().add(l5);
f.getContentPane().add(l6);
f.getContentPane().add(l7);
f.getContentPane().add(l8);
f.getContentPane().add(l9);
f.getContentPane().add(l10);
f.getContentPane().add(l11);
f.getContentPane().add(b1);
f.getContentPane().add(b2);
f.getContentPane().add(h);
f.getContentPane().add(t1);
f.getContentPane().add(t2);
f.getContentPane().add(t3);
f.getContentPane().add(t4);
f.getContentPane().add(t5);
f.getContentPane().add(t6);
f.getContentPane().add(t7);
f.getContentPane().add(li);
f.setSize(1300,1000);
f.setVisible(true);
start();
}
public void start()
{
try
{
st=con.createStatement();
rs=st.executeQuery("select * from Reservation");
while(rs.next())
{
h.add(rs.getString(1));
}
}
catch(Exception e)
{
System.out.println("Connection failed:"+e);
}
}
public void itemStateChanged(ItemEvent e)
{
System.out.println((String)h.getSelectedItem());
try
{
li.removeAll();
ps=con.prepareStatement("select * from Reservation where PNR_No=?");
ps.setString(1,h.getSelectedItem());
rs=ps.executeQuery();
rs.next();
t1.setText(rs.getString(2));
t2.setText(rs.getString(3));
t3.setText(rs.getString(4));
t4.setText(rs.getString(5));
t5.setText(rs.getString(6));
t6.setText(rs.getString(7));
t7.setText(rs.getString(8));
ps=con.prepareStatement("select * from Passenger where PNR_No=?");
ps.setString(1,h.getSelectedItem());
rs=ps.executeQuery();
while(rs.next())
{
li.add(rs.getString(2)+" "+rs.getString(3)+" "+rs.getString(4));
}
}
catch(Exception e1)
{
System.out.println("Connection failed"+e1);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try
{
ps=con.prepareStatement("delete from Reservation where PNR_No=?");
ps.setString(1,h.getSelectedItem());
ps.executeUpdate();
ps=con.prepareStatement("delete from Passenger where PNR_No=?");
ps.setString(1,h.getSelectedItem());
ps.executeUpdate();
JOptionPane.showMessageDialog(null,"Reservation Cancelled");
f.setVisible(false);
}
catch(Exception e1)
{
System.out.println("Connection failed:"+e1);
}
}
if(e.getSource()==b2)
{
f.setVisible(false);
new Main();
}
}
public static void main(String args[])
{
new Cancellation();
}
}import java.sql.*;
public class Connect
{
public Connection con;
public Connect()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=Railway.mdb;DriverID=22");
}
catch(Exception e1)
{
System.out.println("Connection failed:"+e1);
}
}
}
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
class Enquiry extends Connect implements ActionListener
{
JFrame f;
JLabel l1,l2;
JTextField t;
List li;
JButton b1,b2;
PreparedStatement ps;
ResultSet rs;
JLabel imgL;
ImageIcon img;
Enquiry()
{
img=new ImageIcon("LOGO1.jpg");
imgL=new JLabel(img);
imgL.setBounds(0,340,500,200);
f=new JFrame("PNR-Enquiry");
f.getContentPane().setLayout(null);
f.getContentPane().setBackground(Color.green);
l1=new JLabel("PNR No");
l1.setBounds(50,50,60,30);
l2=new JLabel("PNR Details");
l2.setBounds(50,80,100,30);
t=new JTextField(10);
t.addActionListener(this);
t.setBounds(110,50,150,30);
li=new List();
li.setBounds(50,110,390,180);
b1=new JButton("Check");
b1.setBackground(Color.yellow);
b1.addActionListener(this);
b1.setBounds(70,300,100,30);
b2=new JButton("Back");
b2.setBackground(Color.yellow);
b2.addActionListener(this);
b2.setBounds(210,300,100,30);
b1.setMnemonic('C');
b2.setMnemonic('B');
f.getContentPane().add(l1);
f.getContentPane().add(l2);
f.getContentPane().add(t);
f.getContentPane().add(li);
f.getContentPane().add(b1);
f.getContentPane().add(b2);
f.getContentPane().add(imgL);
f.setSize(1300,1000);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
try
{
//reservation information
ps=con.prepareStatement("select * from Reservation where PNR_No=?");
ps.setString(1,t.getText());
rs=ps.executeQuery();
rs.next();
li.clear();
li.add("Train No.: "+rs.getString(2));
li.add("Train Name: "+rs.getString(3));
li.add("Class: "+rs.getString(4));
li.add("Date of Journey: "+rs.getString(5));
li.add("From: "+rs.getString(6));
li.add("To: "+rs.getString(7));
li.add("Boarding at: "+rs.getString(8));
//passeneger information
ps=con.prepareStatement("select * from Passenger where PNR_No=?");
ps.setString(1,t.getText());
rs=ps.executeQuery();
while(rs.next())
{
li.add("Passenger Name: "+rs.getString(2));
li.add("Age: "+rs.getString(3));
li.add("Gender: "+rs.getString(4));
}
}
catch(Exception e1)
{
System.out.println("connection failed:"+e1);
}
}
if(e.getSource()==b2)
{
f.setVisible(false);
new Main();
}
}
public static void main(String args[])
{
new Enquiry();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.