Skip to main content

Tugas 3 PBO-A Membuat Ticket Machine

Berikut saya sertakan codingan saya dalam membuat Ticket Machine di BluJ

Saya membuat 2 class, class pertama untuk TicketMachine, class 2 untuk main.
Class Ticket Machine, memiliki codingan seperti ini:

 /**  
  * Write a description of class ticket_machine here.  
  *  
  * @author Bobbi Aditya  
  * @version 1.0   
  */  
 public class TicketMachine   
  {   
  // The price of a ticket from this machine.   
  public int price;   
  // The amount of money entered by a customer so far.   
  public int balance;   
  // The total amount of money collected by this machine.   
  public int total;   
  /**   
  * Create a machine that issues tickets of the given price.   
  * Note that the price must be greater than zero, and there   
  * are no checks to ensure this.   
  */   
  public TicketMachine(int ticketCost)   
  {   
  price = ticketCost;   
  balance = 0;   
  total = 0;   
  }   
  /**   
  * Return the price of a ticket.   
  */   
  public int getPrice()   
  {  
  System.out.println("Ticket Price:"+price+" cents");  
  System.out.println ("##################");  
  return price;   
  }   
  /**   
  * Return the amount of money already inserted for the   
  * next ticket.   
  */   
  public int getBalance()   
  {  
   System.out.println("Your Balance:"+balance+" cents");  
   System.out.println("You need to insert "+(price-balance)+" cents more");  
   System.out.println ("##################");  
   return balance;   
  }   
  /**   
  * Receive an amount of money in cents from a customer.   
  */   
  public void insertMoney(int amount)   
  {   
   balance = balance + amount;  
   System.out.println (+amount+" cents inserted");  
   System.out.println ("##################");  
  }   
  /**   
  * Print a ticket.   
  * Update the total collected and   
  * reduce the balance to zero.   
  */   
  public void printTicket()   
  {  
    if(balance>=price)  
    {  
   // Simulate the printing of a ticket.   
   System.out.println ("##################");  
   System.out.println ("The KA Line");  
   System.out.println ("Ticket go to AA station");  
   System.out.println (+ price +" cents.");  
   System.out.println ("Enjoy your trip!!");  
   System.out.println ("##################");  
   // Update the total collected with the balance.   
   total = total + balance;   
   // Clear the balance.   
   balance = 0;   
 }  
   else{  
  System.out.println("Ticket can't be printed");  
  System.out.println("You must insert at least: " +(price-balance)+" cents.");  
  System.out.println ("##################");      
   }   
  }  
 }  

Class main, memiliki codingan seperti ini
 /**  
  * Write a description of class main here.  
  *  
  * @author Bobbi Aditya  
  * @version 1.0  
  */  
    import java.util.Scanner;   
  public class IntMain   
  {   
  public static void main(String args[])   
  {   
  Scanner scan= new Scanner(System.in);   
  int cost,menu,balance;   
  System.out.println("Masukkan harga tiket \n");   
  cost=scan.nextInt();  
  TicketMachine ticket=new TicketMachine(cost);  
  balance=ticket.balance;  
  //cost=ticket.getPrice();  
  System.out.println("1. Get Price");   
  System.out.println("2. Get Balance");   
  System.out.println("3. Insert Money");   
  System.out.println("4. Print Ticket");   
  while(true)  
  {  
    menu=scan.nextInt();  
    if(menu==1)  
    {  
      ticket.getPrice();  
    }  
    else if(menu==2)  
    {  
      ticket.getBalance();  
    }  
    else if(menu==3)  
    {  
      int money=scan.nextInt();  
      ticket.insertMoney(money);  
    }  
     else if(menu==4)  
    {  
      ticket.printTicket();  
      break;  
    }  
   }  
 }  
 }  
Outputnya, saya menggunakan harga tiket 300, kemudian saya mengecek balance saya. Setelah itu saya mengisikan uang sejumlah 150. kemudian saya kembali mengecek balance saya. Kemudian saya mengisikan kembali uang sejumlah 150. Dan yang terakhir saya mengeprint ticket yang sudah dibayarkan.
Outputnya adalah:
Nama : Bobbi Adittya
NRP : 05111740000099
Kelas : PBO A

Comments

Popular posts from this blog

MPPL 9 - Manajemen Biaya

Kelas : MPPL C Jeremy Vijay - 05111740000062 Raja Permata Boy - 05111740000070 Bobbi Aditya - 05111740000099 Samuel Marcellinus - 05111740000134 Bastian Farandy - 05111740000190 Link Spreadsheet : SpreadSheet

MPPL - Pengalaman proyek

Nama : Bobbi Aditya Kelas : MPPL-C NRP : 05111740000099 Berikut ini adalah proyek yang saya ketahui Nama Proyek :   Pembangunan Aplikasi MSO (Maintenance System Online) Berbasis Web Deskripsi : Aplikasi ini berguna untuk pemantauan alat-alat yang ada pada PT. Semen Indonesia - Gresik apabila terjadi kerusakan yang harus segera dilaporkan, atau terdapat jadwal pemeliharaan rutin. Lokasi : PT. Semen Indonesia (Persero) Tbk. - Gresik Jl. Veteran, Gresik Jawa Timur, 61122 Waktu Proyek: 02 - 31 Januari 2019 Tim yang terlibat: Almas Aqmarina 05111640000171 Daniel Kurniawan 0511164000081 Produk yang dihasilkan: Sebuah aplikasi yang berada di dalam server Semen Indonesia yang berguna untuk melakukan pemantuan terhadap alat-alat yang ada pada PT. Semen Indonesia. Untuk addressnya tidak bisa diakses dari luar jaringan PT. Semen Indonesia. Fitur: • Tabel Laporan Harian • Pengelolaan Laporan Harian (tambah, ubah, hapus) • Unduh dala