Sunday, October 14, 2018

ETS PBO - SIstem Parkir

7:58 PM Posted by Unknown No comments
 Class yang digunakan
  1. Class Vehicle, merupakan class untuk input jenis kendaraan, nopol, serta durasi parkir
  2. Class Input Reader, sebagai class untuk melakukan input
  3. Class ParkingMachine, merupakan class yang berupa mesin parkir, dimana class ini menjadi pusat pengaturan operasi-operasi dan obyek-obyek pada mesin

  • Class Vehicle
 public class Vehicle   
 {   
   private InputReader reader;   
   public int gvehicle = 0;   
   public int durasi = 0;   
   public String nopol;   
   public void createVehicle(){   
    reader = new InputReader();   
    gvehicle = getVehicle();   
    nopol = getNopol();   
    durasi = getDurasi();   
   }   
   public int getVehicle(){   
     System.out.println("Pilih jenis kendaraan anda:");   
     System.out.println("1. Motor");   
     System.out.println("2. Mobil");   
     int gvehicle = reader.getInt();   
    return gvehicle;   
   }   
   public String getNopol(){   
    System.out.println("Silakan masukkan nomor polisi kendaraan anda: ");   
     String nopol = reader.getInput();   
    return nopol;   
   }   
   public int getDurasi(){   
    System.out.println("Durasi Parkir (dalam jam):");   
    int durasi = reader.getInt();   
    return durasi;   
   }   
 }  

  • Class InputReader
 import java.util.Scanner;   
 public class InputReader   
 {   
    public String getInput()   
 {   
    Scanner sc = new Scanner(System.in);   
    String input = sc.nextLine();   
    return input;   
 }   
 public int getInt(){   
    Scanner sc = new Scanner(System.in);   
    int input = sc.nextInt();   
    return input;   
   }   
 }   

  • Class ParkingMachine
 import java.util.Scanner;   
 public class ParkingMachine   
 {   
   private InputReader reader;   
   private Vehicle vehicle;   
   private int biaya = 0;   
 public ParkingMachine()   
 {   
    reader = new InputReader();   
    vehicle = new Vehicle();   
 }   
 public void start()   
 {   
    printWelcome();   
    vehicle.createVehicle();   
    biaya = 2000*vehicle.gvehicle*vehicle.durasi;    
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );   
    System.out.println("Tekan enter untuk melanjutkan");   
    reader.getInput();   
    System.out.println("Silakan tempelkan kartu pembayaran anda");   
    System.out.println("Tekan enter untuk melanjutkan");  
    reader.getInput();   
    printTicket();   
 }   
 private void printWelcome(){   
    System.out.println("Selamat Datang");   
 }   
 public void printTicket(){    
    System.out.println("------------Tiket 1-----------");  
    System.out.println("---Sistem Parkir Elektronik---");   
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );    
    System.out.println("-------------------------------");   
    System.out.println();    
    System.out.println("------------Tiket 2-----------");  
    System.out.println("---Sistem Parkir Elektronik---");   
    System.out.println("Jenis kendaraan : " + vehicle.gvehicle);   
    System.out.println("Nomor polisi : " + vehicle.nopol);   
    System.out.println("Durasi   : " + vehicle.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp" + biaya );    
    System.out.println("------------------------------");   
   }   
 }  


Berikut tampilan workspace


 NB : tarif parkir yang dikenakan adalah Rp2000,- per jam

Sunday, October 7, 2018

Tugas PBO - Support System

7:44 PM Posted by Unknown No comments
Class yang digunakan :

  1. Class SupportSystem, sebagai main class untuk menjalankan program dan tempat proses support system dilakukan
  2. Class InputReader, berisi input dari pengguna
  3. Class Responder, berisi respon dari sistem setelah pengguna melakukan input

  • Class SupportSystem
 public class SupportSystem  
 {  
   private InputReader reader;  
   private Responder responder;  
    /**  
    * Creates a technical support system.  
    */  
   public SupportSystem()  
   {  
     reader = new InputReader();  
     responder = new Responder();  
   }  
    /**  
    * Start the technical support system. This will print a  
    * welcome message and enter into a dialog with the user,  
    * until the user ends the dialog.  
    */  
   public void start()  
   {  
     boolean finished = false;  
     printWelcome();  
     while(!finished) {  
       String input = reader.getInput();  
       if(input.startsWith("bye")) {  
         finished = true;  
       }  
       else {  
         String response = responder.generateResponse();  
         System.out.println(response);  
       }  
     }  
     printGoodbye();  
   }  
    /**  
    * Print a welcome message to the screen.  
    */  
   private void printWelcome()  
   {  
     System.out.println(  
     "Welcome to the DodgySoft Technical Support System.");  
     System.out.println();  
     System.out.println("Please tell us about your problem.");  
     System.out.println(  
     "We will assist you with any problem you might have.");  
     System.out.println(  
     "Please type 'bye' to exit our system.");  
   }  
    /**  
    * Print a good-bye message to the screen.  
    */  
   private void printGoodbye()  
   {  
     System.out.println("Nice talking to you. Bye. . .");  
   }  
 }  

  • Class InputReader
 import java.util.Scanner;  
 public class InputReader  
 {  
   private Scanner sc;  
   public InputReader(){  
     sc = new Scanner(System.in);  
   }  
   public String getInput(){  
     String input;  
     input = sc.nextLine();  
     return input;  
   }   
 }  

  • Class Responder
 public class Responder  
 {  
    /**  
    * Construct a Responder - nothing to do  
    */  
   public Responder()  
   {  
   }  
    /**  
    * Generate a response.  
    * @return A string that should be displayed as the  
    * response  
    */  
   public String generateResponse()  
   {  
     return "That sounds interesting. Tell me more. . .";  
   }  
 }  




Tugas PBO - Auction System

10:56 AM Posted by Unknown No comments
Class yang digunakan :
  1. Class Auction, sebagai class utama tempat proses auction (pelelangan) dilakukan
  2. Class Lot, berfungsi mendaftarkan dan menyimpan deskripsi lot
  3. Class Person, berfungsi tempat menyimpat data / informasi orang
  4. Class Bid, berfungsi tempat menyimpan nilai bid
  • Class Auction
 /**  
  * Write a description of class Auction here.  
  *  
  * @author Bima S. Ramadhan  
  * @version 1.0  
  */  
 import java.util.ArrayList;  
 public class Auction  
 {  
   private ArrayList<Lot> lots;  
   private int nextLotNumber;  
   //Constructor  
   public Auction()  
   {  
     lots = new ArrayList<Lot>();  
     nextLotNumber = 1;  
   }  
   //Mendaftarkan lot baru  
   public void enterLot(String description)  
   {  
     lots.add(new Lot(nextLotNumber, description));  
     nextLotNumber++;  
   }  
   //Print Semua Lot  
   public void showLots()  
   {  
     for(Lot lot : lots) {  
       System.out.println(lot.toString());  
     }  
   }  
   //Melakukan Bid pada suatu Lot  
   public void makeABid(int lotNumber, Person bidder, long value)  
   {  
     Lot selectedLot = getLot(lotNumber);  
     if(selectedLot != null) {  
       Bid bid = new Bid(bidder, value);  
       boolean successful = selectedLot.bidFor(bid);  
       if(successful) {  
         System.out.println("Bid untuk Lot pada urutan " +  
          lotNumber + " sukses didaftarkan.");  
       }  
       else {  
         Bid highestBid = selectedLot.getHighestBid();  
         System.out.println("Lot urutan ke: " + lotNumber +  
         " memiliki Bid sebesar: " +  
         highestBid.getValue());  
       }  
     }  
   }  
   //Mencari Lot yang terdaftar  
   public Lot getLot(int lotNumber)  
   {  
     if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {  
       Lot selectedLot = lots.get(lotNumber-1);  
       if(selectedLot.getNumber() != lotNumber) {  
          System.out.println("Internal error: Lot urutan ke " +  
         selectedLot.getNumber() +  
         " dimunculkan, sebagai ganti dari " +  
         lotNumber);  
         selectedLot = null;  
       }  
       return selectedLot;  
     }  
     else {  
       System.out.println("Lot urutan ke: " + lotNumber +  
       " tidak ditemukan.");  
       return null;  
     }  
   }  
   public void close()    
   {    
     System.out.println("Closing auction.");    
     for (Lot lot : lots)    
     {     
        System.out.println(lot.getNumber() + ": " + lot.getDescription());    
          if (lot.getHighestBid() == null)    
          {    
            System.out.println (" (No bids) ");    
          }    
          else    
          {    
            Bid highestBid = lot.getHighestBid();    
            System.out.println(" sold to " + highestBid.getBidder().getName() + " for " + highestBid.getValue());    
          }    
     }    
   }     
 }  

  • Class Lot
 /**  
  * Write a description of class Lot here.  
  *  
  * @author Bima S. Ramadhan  
  * @version 1.0  
  */  
 public class Lot  
 {  
   //ID Lot  
   private final int number;  
   //Deskripsi dari sebuah Lot  
   private String description;  
   //Bid tertinggi dari Lot  
   private Bid highestBid;  
   //Constructor  
   public Lot(int number, String description)  
   {  
     this.number = number;  
     this.description = description;  
     this.highestBid = null;  
   }  
   public boolean bidFor(Bid bid)  
   {  
     if(highestBid == null) {  
       //Bid belum ada  
       highestBid = bid;  
       return true;  
     }  
     else if(bid.getValue() > highestBid.getValue()) {  
       //Bid lebih besar dari nilai Bid sebelumnya  
       highestBid = bid;  
       return true;  
     }  
     else {  
       //Bid lebih kecil dari nilai Bid sebelumnya  
       return false;  
     }  
   }  
   //Deskripsi rincian Lot  
   public String toString()  
   {  
     String details = number + ": " + description;  
     if(highestBid != null) {  
       details += "  Bid: " +  
             highestBid.getValue();  
     }  
     else {  
       details += "  (No bid)";  
     }  
     return details;  
   }  
   //Return ID Lot  
   public int getNumber()  
   {  
     return number;  
   }  
   //Return Deskripsi Lot  
   public String getDescription()  
   {  
     return description;  
   }  
   //Return Bid tertinggi  
   public Bid getHighestBid()  
   {  
     return highestBid;  
   }  
 }  

  • Class Person
 /**  
  * Write a description of class Person here.  
  *  
  * @author Bima S. Ramadhan  
  * @version 1.0  
  */  
 public class Person  
 {  
   //variable final untuk nama orang (1 kali inisialisasi)  
   private final String personname;  
   //constructor  
   public Person(String name)  
   {  
     this.personname = name;  
   }  
   //value berupa nama orang  
   public String getName()  
   {  
     return personname;  
   }  
 }  

  • Class Bid 
 /**  
  * Write a description of class Bid here.  
  *  
  * @author Bima S. Ramadhan  
  * @version 1.0  
  */  
 public class Bid  
 {  
   //variable yang hanya bisa diinisialisasi 1 kali  
   private final Person biddername;  
   private final long value;  
   public Bid(Person name, long v)  
   {  
     this.biddername = name;  
     this.value = v;  
   }  
   //value nama bidder  
   public Person getBidder()  
   {  
     return biddername;  
   }  
   //value berupa nilai bid  
   public long getValue()  
   {  
     return value;  
   }  
 }