PBO-4-Class dan Object studi kasus Ticket Machine

Ticket Machine adalah sebuah mesin seperti ATM, yang berfungsi melayani penjualan tiket kereta api dari satu tujuan ke tujuan yang lain. Di dalam Ticket Machine ada sebuah program atau perangkat lunak yang mengatur harga tiket di tiap tujuan, mengatur kembalian uang, dan juga mencetak receipt sebagai bukti pembelian tiket.

Untuk lebih memahami penggunaan class dan object, buatlah projek naive-ticket-machine seperti di dalam buku Object First ini pada bab 2. Buku object first bisa di download di sini.

Projek naive-ticket-machine ini menggambarkan mesin tiket pada stasiun kereta api yang akan mencetak tiket setelah pelanggan memasukkan sejumlah uang yang tepat sesuai dengan harga karcis. Mesin akan terus bekerja menjumlahkan total uang yang berhasil dikumpulkan.


Latihan


Setelah mendownload dan membaca materi Ticket Machine pada buku Object First, coba implementasikan programnya menggunakan BlueJ. Setelah selesai buat link hasil pekerjaan pada bagian comment blog ini.

Kode Program

 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;  
 /**  
 * 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()  
 {  
  return price;  
 }  
 /**  
 * Return the amount of money already inserted for the  
 * next ticket.  
 */  
 public int getBalance()  
 {  
   return balance;  
 }  
 /**  
 * Receive an amount of money in cents from a customer.  
 */  
 public void insertMoney(int amount)  
 {  
   balance = balance + amount;  
 }  
 /**  
 * Print a ticket.  
 * Update the total collected and  
 * reduce the balance to zero.  
 */  
 public void printTicket()  
 {  
   // Simulate the printing of a ticket.  
   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;  
 }  
 }  
 //Main  
 import java.util.Scanner;  
 public class IntMain  
 {  
 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 Price”);  
  System.out.println(“2. Get Balance”);  
  System.out.println(“3. Insert Money”);  
  System.out.println(“4. Print Ticket”);  
  menu=scan.nextInt();  
  switch(menu)  
  {  
   case 1:  
   cost=ticket.getPrice();  
   System.out.println(cost);  
   break;  
   case 2:  
   ticket.getBalance();  
   break;  
   case 3:  
   int money=scan.nextInt();  
   ticket.insertMoney(money);  
   break;  
   case 4:  
   ticket.printTicket();  
   break;  
  }  
  }  
 }  

Jika masih belum bisa atau gagal bisa membuka link Youtube di bawah ini, dan jika ada pertanyaaan bisa melalui WA ataupun twitter. Selamat belajar.



Share this

Related Posts

Previous
Next Post »

232 komentar

komentar «Oldest   ‹Older   201 – 232 of 232   Newer›   Newest»
October 2, 2019 at 5:55 PM delete This comment has been removed by the author.
avatar
October 2, 2019 at 5:56 PM delete

Nama : Risky Aswi Narni
NRP : 05111740000014
Kelas: PBOA
Tugas Ticket Machine Sederhana
Link

Reply
avatar
October 2, 2019 at 5:58 PM delete

Nama : Ignatius Dwiki Iskandar
NRP : 05111840000019
Kelas : PBO D
Link : Ticket Machine

Reply
avatar
October 2, 2019 at 6:02 PM delete

Nama : Ivan Abdillah Rahman
NRP : 05111840000137
Kelas : PBO A
Link : Ticket Machine

Reply
avatar
October 2, 2019 at 6:28 PM delete

Nama : Dicky Maulana Rozi
NRP : 05111740000083
Kelas : PBO A
Link : https://dickymaulanarozi.blogspot.com/2019/09/tugas-3-pbo-a.html

Reply
avatar
October 2, 2019 at 6:29 PM delete This comment has been removed by the author.
avatar
October 2, 2019 at 6:32 PM delete This comment has been removed by the author.
avatar
October 2, 2019 at 6:36 PM delete

Nama : Imanuel Banifernando Simatupang
NRP : 05111840000085
Kelas : PBO D
link :Link Tugas

Reply
avatar
October 2, 2019 at 7:02 PM delete

Nama : Muhammad Satryo Pamungkas Bimasakti
NRP : 05111840000070
Kelas : PBO D
Link : Link Tugas Ticket Machine

Reply
avatar
October 2, 2019 at 7:10 PM delete

Nama : Putu Putri Natih Devayanti
NRP : 05111840000163
Kelas : PBO A
Link : Ticket Machine

Reply
avatar
October 2, 2019 at 7:20 PM delete This comment has been removed by the author.
avatar
October 2, 2019 at 7:24 PM delete

Nama : Aflakah Nur Farhana
NRP : 05111840000120
Kelas : PBO D
link : tugas ticket machine

Reply
avatar
October 2, 2019 at 7:26 PM delete

Nama : Elvira Catrine Natalie
NRP : 05111840000016
Kelas : PBO-A
Link : Ticket Machine

Reply
avatar
October 2, 2019 at 7:29 PM delete This comment has been removed by the author.
avatar
October 2, 2019 at 7:36 PM delete

Nama : Achmad Sofyan Pratama
NRP : 05111740000061
Kelas : PBO D
Link : tugas 3 pbo ticket machine

Reply
avatar
October 2, 2019 at 8:08 PM delete

Nama: Julius
Kelas: PBO A
NRP: 05111840000082
link: Tugas Ticket Machine

Reply
avatar
October 2, 2019 at 8:50 PM delete

Nama : Adam Abelard Garibaldi
NRP : 05111840000125
Kelas : PBO A
Link : Tugas Ticket Machine

Reply
avatar
October 2, 2019 at 10:32 PM delete

Nama : Nikodemus Siahaan
NRP : 05111840000151
Kelas: PBO-A
Link : Ticket Machine

Reply
avatar
October 3, 2019 at 2:46 AM delete

Nama : Salsabila Harlen
NRP : 05111840000127
Kelas : PBO A
Link : Tugas Ticket Machine

Reply
avatar
October 3, 2019 at 6:51 AM delete This comment has been removed by the author.
avatar
October 3, 2019 at 6:53 AM delete This comment has been removed by the author.
avatar
October 6, 2019 at 10:45 PM delete

Nama : Philip Antoni Siahaan
NRP : 05111740000111
Kelas : PBO A
Link : Tugas Ticket Machine

Reply
avatar
October 9, 2019 at 9:12 PM delete

Nama : David Bintang Krishanindito
NRP : 05111840000090
Kelas : PBO D
Link : Tugas Ticket Machine

Reply
avatar
October 17, 2019 at 5:43 AM delete

Nama : Muhammad Rayhan Hakim
NRP : 05111740000160
Kelas : PBO A
Tugas : Ticket Machine
Link : https://gipenhakim.blogspot.com/2019/10/ticket-machine-pada-tugas-kali-ini-saya.html

Reply
avatar
October 17, 2019 at 5:48 AM delete This comment has been removed by the author.
avatar
October 23, 2019 at 8:16 AM delete

Nama: Abdul Rozak Baharudin
NRP: 05111840000148
Kelas: PBO D
Link: Link Tugas PBO 3

Reply
avatar
November 13, 2019 at 6:16 PM delete

Aaron Astonvilla Rompis
05111840000131
PBO D
Link

Reply
avatar
November 24, 2019 at 5:29 PM delete

Nama : Muhammad Ilham Indiano
NRP : 05111740000177
Kelas : PBO A
Tugas : Ticket Machine
Mesin Tiket

Reply
avatar
November 27, 2019 at 9:35 PM delete

Nama : Ammar Alifian Fahdan
NRP : 05111840000007
Kelas : PBO A
Link : Tugas

Reply
avatar
December 14, 2019 at 9:39 PM delete This comment has been removed by the author.
avatar
December 17, 2019 at 6:49 AM delete

Nama : M Yusuf Mukharom
NRP : 05111740000051
Kelas : Ticket Machine

Reply
avatar
«Oldest   ‹Older   201 – 232 of 232   Newer›   Newest»