title: ticket machine in netbeans
body: <p>I need some help in making this ticket machine code work. I can do it using if, else if and else, and I have seen it done with a while loop. However whenever I am trying to run it as an object I either get and error because of the print ticket at the bottom of the code, or build successful and no ticket. Here is my code</p>
  
  <pre><code>package ticketmachine;
  
  import javax.swing.JOptionPane;
  
  
  public class TicketMachine {
      private int price;
      private int change;
      private int balance;
  
  public int getPrice(){
      return price;
  }
  
  public int getBalance(){
      return balance;
  }
  
  public TicketMachine (int ticketCost) {
      price = ticketCost;
      change = 0;
      balance = 0;
  }
  
  public void insertMoney (int amount){
      balance = balance + amount;
  }    
  
  public static void main(String[] args){ 
  
      String input1= JOptionPane.showInputDialog(null, " Insert a coin ");
      int ticketCost=Integer.parseInt(input1);
  
  
  public void printTicket(){
  
      //Simulate the printing of a ticket
      System.out.println("##################");
      System.out.println("# Ticket");
      System.out.println("# " + price + " pence.");
      System.out.println("##################");
      System.out.println();
  }
  }        
  }        
  </code></pre>