Pada tanggal 17 September 2018, lebih tepatnya jam 11.00 tadi saya diberikan tugas untuk membuat software mesin tiket
1. Foto classnya
2. Kodingan Class TicketMachine
 /**  
  * software for TicketMachine  
  *  
  * @author M Thalut Nadhil Q  
  * @version 3  
  */  
 public class TicketMachine   
 {   
   // The price of a ticket from this machine   
   private int price;   
   // The amount of money entered by a customer so far.   
   private int balance;   
   // The total amount of money collected by this machine.   
   private int total;   
   public TicketMachine(int ticketCost)   
   {   
     price = ticketCost;   
     balance = 0;   
     total = 0;   
   }   
   public int getPrice()   
   { return price; }   
   public int getBalance()   
   { return balance;}   
   public void insertMoney(int amount)   
   { balance = balance + amount; }   
   public void printTicket()   
   {   
     System.out.println("################");   
     System.out.println("# The BlueJ Line");   
     System.out.println("# Ticket");   
     System.out.println("#" + price + " cents.");   
     System.out.println("#################");   
     System.out.println();   
     // Update the total collected with the balance.   
     total = total + balance;   
     // Clear the balance.   
     balance = 0;  
   }   
  }  
3. Kodingan Class Mainnya
 /**  
  * software for TicketMachine  
  *  
  * @author M Thalut Nadhil Q  
  * @version 3  
  */  
 //Main   
  import java.util.Scanner;   
  public class IntMain   
  {   
    public static int main(String args[])   
    {   
      Scanner scan= new Scanner(System.in);   
      int cost, menu, money;   
      System.out.println("Masukkan harga tiket \n");   
      cost=scan.nextInt();   
      TicketMachine ticket=new TicketMachine(cost);   
      while(true)   
      {   
        System.out.println("1. Get Price");   
        System.out.println("2. Get Balance");   
        System.out.println("3. Insert Money");   
        System.out.println("4. Print Ticket");   
        System.out.println("5. Exit");   
        menu=scan.nextInt();   
        switch(menu)   
        {     
          case 1:   
          cost=ticket.getPrice();   
          System.out.println(cost);   
          break;   
          case 2:   
          System.out.println(ticket.getBalance());   
          break;   
          case 3:   
          money = scan.nextInt();   
          ticket.insertMoney(money);   
          break;   
          case 4:   
          ticket.printTicket();   
          break;   
          case 5:   
          return 0;   
         }   
       }     
    }   
  }   
4. Foto hasil outputnya

Komentar

Postingan populer dari blog ini

UTS PBKK A

Tugas 2 PBKK