TUGAS PBO MESIN TIKET :

ZAHRUL ZIZKI DINANTO
05111740000168

BERIKUT ADALAH SOURCE CODE UNTUK MESIN TIKET :

 import java.util.Scanner;  
   
 public class TicketMachine   
  {   
  // untuk menyimpan harga
  private int harga;   
  // untuk menghitung uang setelah ditambah atau dikurang.   
  private int balance;   
  // tunuk total.   
  private int total;   
  //untuk  menginputkan harga  
  public TicketMachine(int HargaTiket)   
  {   
  harga = HargaTiket; balance = 0;   
  total = 0;   
  }   
  
 //untuk melihat harga
  public int getharga()   
  {   
  return harga;   
  }   
 //untuk melihat hasil setelah ditambah atau dikurang
  public int getBalance()   
  {   
   return balance;   
  }   
  //untuk menginsertkan uang sipembeli
  public void insertMoney(int amount)   
  {   
   balance = balance + amount;   
  }   
  /**   
  * Print a ticket.   
  * Update the total collected and   
  * reduce the balance to zero.   
  */   
  public void printTicket()   
  {   
   System.out.println("##################");   
   System.out.println("# KERETA API ");   
   System.out.println("# Ticket");   
   System.out.println("# " +harga+ " Rupiah.");   
   System.out.println("Kembalianmu "+balance+ " Rupiah");  
   System.out.println("##################");   
      
   total = total + balance;   
   // mengembalikan jadi 0.   
   balance = 0;   
  }   
  
  //untuk main
  public static void main(String args[])   
  {   
  Scanner scan= new Scanner(System.in);   
  int cost,menu;   
  System.out.println("Masukkan harga tiket \n");   
  cost=scan.nextInt();   
  TicketMachine ticket=new TicketMachine(cost);  
  System.out.println("1. Get harga");   
  System.out.println("2. Get Balance");   
  System.out.println("3. Insert Money");   
  System.out.println("4. Print Ticket");   
  System.out.println("5. Exit");  
  int x=1;  
  while(x == 1){  
    menu = scan.nextInt();  
    switch(menu)   
  {   
   case 1:   
   cost=ticket.getharga();   
   System.out.println(cost);   
   break;   
   case 2:   
   System.out.print(ticket.getBalance()+"\n");   
   break;   
   case 3:   
   int money=scan.nextInt();   
   ticket.insertMoney(money);   
   break;   
   case 4:   
   cost = ticket.getharga();  
   ticket.balance = ticket.balance - cost;  
   ticket.printTicket();   
   break;   
   case 5:  
   x=0;break;  
  }   
  
 }  
 }  
 }  


Berikut adalah Screen Shoot :




Komentar

  1. How to get to the Grand Mondial Casino via Bus from
    from the nearest airport to 골인 벳 먹튀 you is the Grand 사다리 사이트 Mondial Casino. The best 오피주소 way to 잭팟 do this is to just hop into the grandstand and clubw88 take your ticket.

    BalasHapus

Posting Komentar

Postingan populer dari blog ini