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;
    }
   
       
}

well .. what do you think your setters and getters are for, if not to exchange information between several classes?

they are but it isn't working so I was hoping someone could give me insite as to why its not, or if I'm going about it completely wrong

it isn't working

Can you explain what the program does and what is wrong?

Try debugging the program by adding println statements to show the values of variables as they are used and changed. The print out will show you what the program is doing so that you can see where the problem is.

I have done that but it does not display the user inputs or the calculations of the inputs I'm so confused been staring at it forever

Edit: nevermind, sorry made a wrong post

Post the output from the program that shows what it is doing. You probably do not have enough printlns to show what you need to see.
If it does not print out the users inputs, does it throw an exception?

ok I changed them around still not working here is all the errors


Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Report.outputMe(Report.java:62)
at TicketForm.createReport(TicketForm.java:195)
at TicketForm.actionPerformed(TicketForm.java:176)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:6290)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
at java.awt.Component.processEvent(Component.java:6055)
at java.awt.Container.processEvent(Container.java:2039)
at java.awt.Component.dispatchEventImpl(Component.java:4653)
at java.awt.Container.dispatchEventImpl(Container.java:2097)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4236)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166)
at java.awt.Container.dispatchEventImpl(Container.java:2083)
at java.awt.Window.dispatchEventImpl(Window.java:2482)
at java.awt.Component.dispatchEvent(Component.java:4481)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:648)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:607)
at java.awt.EventQueue$1.run(EventQueue.java:605)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98)
at java.awt.EventQueue$2.run(EventQueue.java:621)
at java.awt.EventQueue$2.run(EventQueue.java:619)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:618)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Report.outputMe(Report.java:62)

Look at line 62 in Report and find the variable with the null value. Then backtrack in the code to see why that variable does not have a non null value.

I've only had 10 hours of java training so far and I don't fully understand why it null I have given it a value and it is used

I should also mention this was due last night at 12 I passed in another one that passed the info differently just want to figure out how to do it this way I'm having trouble with me gets and sets

An object reference has a null value by default. If you don't give it a value it will remain null.
If you want to call a method in a class using a reference to that class, that reference must have the address of an instance of the class. If it is null when you use it, you will get a NullPointerException.

Where in the Report class does the variable: seat1 get assigned a value?
If it does not have a value, and you try to execute this statement:
seat1.getQuantity()
you will get a NullPointerException

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.