Kamis, 01 Juni 2017

Final Project Ticket Machine

  1. //class TicketMachine
  2. public class TicketMachine
  3. {
  4.     //the price of a ticket from this machine
  5.     private int price;
  6.     //the amount of money entered by a customer so far
  7.     private int balance;
  8.     //the total amount of money collected by this machine
  9.     private int total;
  10.     private int refund;
  11.     private int tickets;
  12.    
  13.     public TicketMachine(int ticketCost)
  14.     {
  15.         price=ticketCost;
  16.         balance=0;
  17.         total=0;
  18.         refund=0;
  19.         tickets=0;
  20.     }
  21.    
  22.     public int getPrice()
  23.     {
  24.         return price;
  25.     }
  26.    
  27.     public int getBalance()
  28.     {
  29.         return balance;
  30.     }
  31.    
  32.     public void insertMoney(int amount)
  33.     {        if(amount > 0)
  34.         {
  35.             balance += amount;
  36.         }
  37.         else
  38.         {
  39.             System.out.println("Please insert a sensible amount of money.");
  40.         }
  41.     }
  42.    
  43.     public void printTicket()
  44.     {
  45.         if(balance > 0)
  46.         {
  47.             if(balance >= price)
  48.             {
  49.                 tickets = purchaseTickets();
  50.                
  51.                 int i=1;
  52.                
  53.                 while (i <= tickets)
  54.                 {
  55.                     System.out.println("---------------------");
  56.                     System.out.println("--The PBO A Express--");
  57.                     System.out.println("--Ticket " + i );
  58.                     System.out.println("- " + price + " cents. ");
  59.                     System.out.println("---------------------");
  60.                    
  61.                     i++;
  62.                 }
  63.                 total += balance;
  64.                
  65.                 refund = refundBalance();
  66.                
  67.                 if(refund == 0)
  68.                 {
  69.                     System.out.println("No change given.");
  70.                 }
  71.                 else
  72.                 {
  73.                     System.out.println("Amount to refund: " + refund + " cents.");
  74.                 }
  75.                 balance = 0;
  76.                
  77.             }
  78.             else
  79.             {
  80.                 System.out.println("Please insert " + (price -balance) + " more cents.");
  81.             }
  82.         }
  83.         else
  84.         {
  85.             System.out.println("Please insert a positive amount of money.");
  86.         }
  87.     }
  88.    
  89.     public int refundBalance()
  90.     {
  91.         int amountToRefund;
  92.        
  93.         amountToRefund = balance - price * tickets;
  94.        
  95.         balance = 0;
  96.        
  97.         return amountToRefund;
  98.     }
  99.     public int purchaseTickets()
  100.     {
  101.         int numberOfTickets;
  102.        
  103.         numberOfTickets = balance / price;
  104.        
  105.         return numberOfTickets;
  106.     }
  107. }

1 komentar:

  1. The Best On Casino Platforms - Get Love Back Bangal
    On Casino getlovebackbangalibaba.com Platforms - Get Love Back Bangal Bikini. $25.99 Free Shipping. + Shipping. w88 mobile Get on the go, our top bet online 인생도박 casino games you bet for free to you,

    BalasHapus

Rangkuman Buku System Analysis and Design

BAB 3: Requirements Determination -           Fase Analisis Fase analisis menentukan garis besar tujuan bisnis untuk sistem, menentukan...