SHARE
TWEET

Untitled

reyhanzo Dec 15th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class TicketMachine
  2. {
  3.     private int price ;
  4.     private int balance ;
  5.     private int total ;
  6.    
  7.     public TicketMachine ( int cost )
  8.     {
  9.         price = cost;
  10.         balance = 0;
  11.         total = 0;
  12.     }
  13.     public int getPrice()
  14.     {
  15.         return price;
  16.     }
  17.     public int getBalance()
  18.     {
  19.         return balance;
  20.     }
  21.     public void insertMoney ( int amount )
  22.     {
  23.         if (amount > 0)
  24.         {
  25.             balance = balance + amount;
  26.         }
  27.         else
  28.         {
  29.              System.out.println ( "Use a positive amount rather than: " + amount);
  30.         }
  31.     }
  32.     public void printTicket ()
  33.     {
  34.         if (balance >= price)
  35.         {
  36.              System.out.println ( "##################");
  37.              System.out.println ( "# The BlueJ Line");
  38.              System.out.println ( "# Ticket");
  39.              System.out.println ( "# " + price + " cents.");
  40.              System.out.println ( "##################");
  41.              System.out.println ();
  42.              total = total + price;
  43.              balance = balance - amount;
  44.         }
  45.         else
  46.         {
  47.              System.out.println ( "You must insert at least: " + (price - balance) + " cents.");
  48.         }
  49.     }
  50.     public int refundBalance()
  51.     {
  52.          int amountToRefund ;
  53.          amountToRefund = balance;
  54.          balance = 0;
  55.          return amountToRefund;
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top