I have been given a project to create the interface and code for a ticket seat calculator I have to produce the quantity and price which is from a text box on the main frame pass them into the seat class to create the totals then pass it into a report class to create the report i should mention there are 3 seats I need to do this with....here is what I have please help.
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import javax.swing.*;
public class TicketForm extends JFrame implements ActionListener {
//
//importing classes
Report report;
Seat seat1;
Seat seat2;
Seat seat3;
//creating class constants
private static final int FRAME_WIDTH = 450;
private static final int FRAME_HEIGHT = 550;
private static final int FRAME_X = 150;
private static final int FRAME_Y = 250;
public double total;
// form objects
private JButton btnResults;
private JButton btnReset;
private JTextField txtInputA;
private JTextField txtInputB;
private JTextField txtInputC;
private JTextField txtPriceA;
private JTextField txtPriceB;
private JTextField txtPriceC;
private JTextArea txtOutput;
private JLabel lblA;
private JLabel lblB;
private JLabel lblC;
private JLabel lblCount;
private JLabel lblPrice;
private JPanel pnlTop;
private JPanel pnlCenter;
private JPanel pnlBottom;
// -------------------------------------------- constructor method
public TicketForm() {
//Method to calculate the total values for the seats.
report = new Report();
seat1 = new Seat();
seat2 = new Seat();
seat3 = new Seat();
// initializing JFrame properties
this.setTitle("Concert Ticket Calculator");
this.setSize(FRAME_WIDTH,FRAME_HEIGHT);
this.setLocation(FRAME_X,FRAME_Y);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setResizable(false);
// gain reference to the contentPane object of this JFrame
Container contentPane = this.getContentPane();
contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
//Panel to hold our JTextFields and JLabels
pnlTop = new JPanel();
pnlTop.setPreferredSize(new Dimension(425,150));
pnlTop.setBorder(BorderFactory.createTitledBorder("Enter Data"));
//Panel to hold our JTextArea
pnlCenter = new JPanel();
pnlCenter.setPreferredSize(new Dimension(425,310));
pnlCenter.setBorder(BorderFactory.createTitledBorder("Report"));
//Panel to hold our Generate report and Reset buttons
pnlBottom = new JPanel();
pnlBottom.setPreferredSize(new Dimension(425,200));
pnlBottom.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
//Initialize Controls and assign properties
btnResults = new JButton("Create Report");
btnResults.setFont(new Font("Courier",Font.BOLD, 12));
btnResults.setSize(40,20);
btnResults.addActionListener(this);
btnReset = new JButton("Reset");
btnReset.setFont(new Font("Courier",Font.BOLD, 12));
btnReset.setSize(40,20);
btnReset.addActionListener(this);
txtInputA = new JTextField();
txtInputA.setColumns(10);
txtInputA.setFont(new Font("Courier",Font.PLAIN, 12));
txtInputB = new JTextField();
txtInputB.setColumns(10);
txtInputB.setFont(new Font("Courier",Font.PLAIN, 12));
txtInputC = new JTextField();
txtInputC.setColumns(10);
txtInputC.setFont(new Font("Courier",Font.PLAIN, 12));
txtPriceA = new JTextField("27.50");
txtPriceA.setColumns(10);
txtPriceA.setFont(new Font("Courier",Font.PLAIN, 12));
txtPriceA.setFocusable(false);
txtPriceB = new JTextField("19.50");
txtPriceB.setColumns(10);
txtPriceB.setFocusable(false);
txtPriceB.setFont(new Font("Courier",Font.PLAIN, 12));
txtPriceC = new JTextField("15.25");
txtPriceC.setColumns(10);
txtPriceC.setFocusable(false);
txtPriceC.setFont(new Font("Courier",Font.PLAIN, 12));
txtOutput = new JTextArea();
txtOutput.setPreferredSize(new Dimension(405,275));
txtOutput.setFont(new Font("Monochromatic",Font.PLAIN, 12));
txtOutput.setBorder(BorderFactory.createLineBorder(Color.black));
txtOutput.setEditable(false);
lblA = new JLabel("Enter for Seat A:");
lblA.setFont(new Font("Courier",Font.BOLD, 12));
lblA.setBorder(BorderFactory.createEmptyBorder(5, 50, 0, 5));
lblB = new JLabel("Enter for Seat B:");
lblB.setFont(new Font("Courier",Font.BOLD, 12));
lblB.setBorder(BorderFactory.createEmptyBorder(5, 50, 0, 5));
lblC = new JLabel("Enter for Seat C:");
lblC.setFont(new Font("Courier",Font.BOLD, 12));
lblC.setBorder(BorderFactory.createEmptyBorder(5, 50, 0, 5));
lblCount = new JLabel("Count");
lblCount.setFont(new Font("Courier",Font.BOLD, 12));
lblCount.setBorder(BorderFactory.createEmptyBorder(10, 95, 5, 5));
lblPrice = new JLabel("Price ($)");
lblPrice.setFont(new Font("Courier",Font.BOLD, 12));
lblPrice.setBorder(BorderFactory.createEmptyBorder(10, 70, 5, 5));
//Add the panels to the content pane
contentPane.add(pnlTop);
contentPane.add(pnlCenter);
contentPane.add(pnlBottom);
//Add controls to the top panel
pnlTop.add(lblCount);
pnlTop.add(lblCount);
pnlTop.add(lblPrice);
pnlTop.add(lblA);
pnlTop.add(txtInputA);
pnlTop.add(txtPriceA);
pnlTop.add(lblB);
pnlTop.add(txtInputB);
pnlTop.add(txtPriceB);
pnlTop.add(lblC);
pnlTop.add(txtInputC);
pnlTop.add(txtPriceC);
//Add controls to the center panel
pnlCenter.add(txtOutput);
//Add controls to the bottom panel
pnlBottom.add(btnResults);
pnlBottom.add(btnReset);
}
//-------------------------------Action Listener for Create Report and Reset buttons
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Create Report")){
createReport();
}
else if(e.getActionCommand().equals("Reset")){
reset();
}
}
//------------------------------------Report method sending the info to the report class by getting and setting
private void createReport(){
//output = report.report(Double.parseDouble(txtInputA.getText()), Double.parseDouble(txtPriceA.getText()), Double.parseDouble(txtInputB.getText()), Double.parseDouble(txtPriceB.getText()), Double.parseDouble(txtInputC.getText()), Double.parseDouble(txtPriceC.getText()));
seat1.setQuantity(Double.parseDouble(txtInputA.getText()));
seat1.setPrice(Double.parseDouble(txtPriceA.getText()));
seat2.setQuantity(Double.parseDouble(txtInputB.getText()));
seat2.setPrice(Double.parseDouble(txtPriceB.getText()));
seat3.setQuantity(Double.parseDouble(txtInputC.getText()));
seat3.setPrice(Double.parseDouble(txtPriceC.getText()));
txtOutput.setText(report.outputMe());
/*output = "\tTickets Sold\tPrice\tTotal \n" +
"\t- - - - - - - - -\t- - - - - - - -\t- - - - - - - -" +"\n" +
"Seat A\t" + (int)inputA + "\t" + NumberFormat.getCurrencyInstance().format(priceA) +"\t" + NumberFormat.getCurrencyInstance().format(totalA) +"\n"+
"Seat B\t" + (int)inputB + "\t" + NumberFormat.getCurrencyInstance().format(priceB) +"\t" + NumberFormat.getCurrencyInstance().format(totalB) +"\n"+
"Seat C\t" + (int)inputC + "\t" + NumberFormat.getCurrencyInstance().format(priceC) +"\t" + NumberFormat.getCurrencyInstance().format(totalC) +"\n"+"\n"+
"Sales Total" + " " + NumberFormat.getCurrencyInstance().format(total);*/
}
//------------------reset method
private void reset() {
txtInputA.setText("");
txtInputB.setText("");
txtInputC.setText("");
txtOutput.setText("");
}
public static void main(String[] args) {
TicketForm ticketForm;
ticketForm = new TicketForm();
ticketForm.setVisible(true);
}
}
public class Seat {
TicketForm ticketForm;
Seat seat1;
Seat seat2;
Seat seat3;
public double price;
public double quantity;
public double total;
//String totals;
public Seat(){
// initialization
}
// --------------------------------------------------- get/set methods
public double getPrice() {
return price;
}
public void setPrice(double value) {
price = value;
}
public double getQuantity() {
return quantity;
}
public void setQuantity(double value){
quantity = value;
}
public void setTotal(double quantity, double price){
total = quantity * price;
}
public double getTotal(){
return total;
}
}
import java.awt.*;
import java.text.NumberFormat;
import javax.swing.*;
public class Report {
//importing class
//public Report feedback;
public Seat seat1;
public Seat seat2;
public Seat seat3;
//declaring variables
/*public double totalA;
public double totalB;
public double totalC;
private double total;*/
String output;
public Report(){
}
// --------------------------------------------------- get/set methods
public String outputMe() {
String report = "\tTickets Sold\tPrice\tTotal \n" +
"\t- - - - - - - - -\t- - - - - - - -\t- - - - - - - -" +"\n" +
"Seat A\t" + seat1.getQuantity() + "\t" + NumberFormat.getCurrencyInstance().format(seat1.getPrice()) +"\t" + NumberFormat.getCurrencyInstance().format(seat1.getTotal()) +"\n"+
"Seat B\t" + seat2.getQuantity() + "\t" + NumberFormat.getCurrencyInstance().format(seat2.getPrice()) +"\t" + NumberFormat.getCurrencyInstance().format(seat2.getTotal()) +"\n"+
"Seat C\t" + seat3.getQuantity() + "\t" + NumberFormat.getCurrencyInstance().format(seat3.getPrice()) +"\t" + NumberFormat.getCurrencyInstance().format(seat3.getTotal()) +"\n"+"\n"+
"Sales Total" + " " + NumberFormat.getCurrencyInstance().format(seat1.getTotal()+seat2.getTotal()+seat3.getTotal());
return report;
}
}