Minggu, 14 Oktober 2018

UTS PBO

Pada hari ini, saya membuat program sistem parkir elektronik dengan java. berikut hasil dan source codenya.





Class Main

 import java.util.Scanner;  
 /**  
  * Write a description of class Main here.  
  *  
  * @author (Ismail)  
  * @version (15102018)  
  */  
 public class Main  
 {  
   public static void main(String args[])  
   {  
     Scanner scan = new Scanner(System.in);  
     int menu, harga;  
     harga = 2000;  
     SistemParkir tiket = new SistemParkir(harga);  
     System.out.println("Silahkan pilih tombol yang di inginkan \n");  
     System.out.println("Pos Masuk Parkir");  
     System.out.println("1. Parkir");  
     System.out.println("2. Bantuan\n");  
     System.out.println("Pos Keluar Parkir");  
     System.out.println("3. Scan Barcode Keluar");  
     System.out.println("4. Print Bukti Parkir");  
     int tipe=1;  
     while(tipe == 1)  
     {  
       menu = scan.nextInt();  
       switch(menu)  
       {  
         case 1:  
         System.out.println("Masukkan Waktu Parkir (contoh : 1700) : ");  
         int awal = scan.nextInt();  
         tiket.masukparkir(awal);  
         tiket.Tiketparkir();  
         break;  
         case 2:  
         System.out.println("Harap menunggu operator");  
         break;  
         case 3:  
         System.out.println("Masukkan Waktu Keluar Parkir (contoh 1800) : ");  
         int akhir = scan.nextInt();  
         tiket.keluarparkir(akhir);  
         tiket.Scanbarcode();  
         break;  
         case 4:  
         tiket.buktiparkir();  
         tipe=0;  
         break;  
       }  
     }  
   }  
 }  


Class SistemParkir

 /**  
  * Write a description of class SistemParkir here.  
  *  
  * @author (Ismail)  
  * @version (16102018)  
  */  
 public class SistemParkir  
 {  
   private int tiket;  
   private int masuk;  
   private int biaya;  
   private int keluar;  
   public SistemParkir(int harga)  
   {  
     masuk = 0;  
     biaya = harga;  
   }  
   public void Tiketparkir()  
   {  
     System.out.println("##############");  
     System.out.println("Selamat Datang");  
     System.out.println("Waktu Parkir : "+masuk);  
     System.out.println("############");  
   }  
   public int masukparkir(int awal)  
   {  
     return masuk=awal;  
   }  
   public void keluarparkir(int akhir)  
   {  
     keluar = akhir;  
     akhir -= masuk;
     akhir = akhir/1000;  
     biaya += akhir*1000;  
   }  
   public void Scanbarcode()  
   {  
     System.out.println("Biaya Parkir : Rp "+biaya);  
   }  
   public void buktiparkir()  
   {  
     System.out.println("#############");  
     System.out.println("Selamat Jalan");  
     System.out.println("Bukti Parkir");  
     System.out.println("Jam Parkir : "+masuk);  
     System.out.println("Jam Keluar : "+keluar);  
     System.out.println("Rp. "+biaya);  
     System.out.println("#############");  
   }  
 }  

Music Player

Pada kali ini, saya mendapat tugas untuk membuat program music organizer dengan java. Berikut source code dan hasil output programnya.

Class Music Organizer

 import java.util.ArrayList;  
 /**  
  *   
  *  
  * @author (Ismail)  
  * @version (14102018)  
  */  
 public class Musicorganizer  
 {  
   private ArrayList<String> files;  
   private Musicplayer player;  
   //membuat sebuah music organizer  
   public Musicorganizer()  
   {  
     files = new ArrayList<>();  
     player = new Musicplayer();  
   }  
   //menambahkan file ke koleksi  
   public void addFile(String filename)  
   {  
     files.add(filename);  
   }  
   //memasukkan jumlah file ke koleksi  
   public int getNumberOfFiles()  
   {  
     return files.size();  
   }  
   //list file dari koleksi  
   public void listFile(int index)  
   {  
     if(index >= 0 && index < files.size()){  
       String filename = files.get(index);  
       System.out.println(filename);  
     }  
   }  
   //menghapus file di koleksi  
   public void removeFile(int index)  
   {  
     if(index >= 0 && index < files.size()){  
       files.remove(index);  
     }  
   }  
   //memainkan file musik di koleksi  
   public void startPlaying(int index)  
   {  
     String filename = files.get(index);  
     player.startPlaying(filename);  
   }  
   //menghentikan player musik  
   public void stopPlaying()  
   {  
     player.stopPlaying();  
   }  
 }  


Class Music Player

 /**  
  *   
  *  
  * @author (Ismail)  
  * @version (14102018)  
  */  
 public class Musicplayer  
 {  
   private String music;  
   public Musicplayer()  
   {  
     music = null;  
   }  
   public void startPlaying(String filename)  
   {  
     music = filename;  
     System.out.println(music+ " Is Now Playing");  
   }  
   public void stopPlaying()  
   {  
     System.out.println("The Music Stop Playing");  
   }  
 }  


Hasil Output program

1. Menambahkan lagu ke playlist


2. Mengecek list lagu



3. Memainkan dan menghentikan lagu






Selasa, 09 Oktober 2018

Auction

Pada pertemuan kali ini, kami mendapatkan tugas untuk membuat program pelelangan. Berikut hasil dan source code-nya.







Auction

 import java.util.ArrayList;  
 /**  
  * class Auction  
  *  
  * @author (Ismail)  
  * @version (09102018)  
  */  
 public class Auction    
 {    
   private ArrayList<Lot> lots;   
   private int LotNumber;  
   //Membuat Auction baru  
   public Auction()    
   {    
     lots = new ArrayList<Lot>();   
     LotNumber = 1;    
   }  
   //Menambahkan barang baru  
   public void enterLot(String description)    
   {   
     lots.add(new Lot(LotNumber, description));    
     LotNumber++;    
   }  
   //Menampilkan barang yang dilelang  
   public void showLots()  
   {   
     for(Lot lot : lots) {    
      System.out.println(lot.detail());    
     }  
   }  
   //Melakukan tawaran  
   public void MakeBid(int CurrentlotNumber, Person bidder, long value)    
   {    
     Lot selectedLot = getLot(CurrentlotNumber);    
     if(selectedLot != null)  
     {  
       boolean succes = selectedLot.bidFor(new Bid(bidder, value));    
       if(succes)  
       {  
         System.out.println("The bid for lot number " +CurrentlotNumber+ " was successful.");  
       }  
       else  
       {  
         Bid highestBid = selectedLot.getHighestBid();    
         System.out.println("Lot number: " +CurrentlotNumber+ " already has a bid of: " +highestBid.getBid());    
       }  
     }  
   }  
   public Lot getLot(int CurrentlotNumber)    
   {  
     if((CurrentlotNumber >= 1) && (CurrentlotNumber < LotNumber))  
     {  
       Lot selectedLot = lots.get(CurrentlotNumber - 1);   
       if(selectedLot.getId() != CurrentlotNumber)  
       {  
         System.out.println("Internal error: Lot number " +selectedLot.getId()+ " was returned instead of " +CurrentlotNumber);   
         selectedLot = null;    
       }  
       return selectedLot;    
     }  
     else  
     {  
       System.out.println("Lot number : " + CurrentlotNumber +  " does not exist.");    
       return null;    
     }  
   }  
 }  


Person

 /**  
  * class Person  
  *  
  * @author (Ismail)  
  * @version (09102018)  
  */  
 public class Person  
 {  
   private final String name;  
   public Person(String newName)  
   {  
     this.name = newName;  
   }  
   public String getName()  
   {  
     return name;  
   }  
 }  


Lot

 /**  
  * Class Lot  
  *  
  * @author (Ismail)  
  * @version (09102018)  
  */  
 public class Lot  
 {  
   private final int Id;  
   private String description;  
   private Bid highestBid;  
   public Lot(int number, String description)  
   {  
     this.Id = number;  
     this.description = description;  
   }  
   public boolean bidFor(Bid bid)  
   {  
     if((highestBid ==null) || (bid.getBid() > highestBid.getBid()))  
     {  
       highestBid = bid;  
       return true;  
     }  
     else  
     {  
       return false;  
     }  
   }  
   public String detail()  
   {  
     String details = Id+ ": " +description;  
     if(highestBid != null)  
     {  
       details += " Bid: " +highestBid.getBid();  
     }  
     else  
     {  
       details += " (No Bid)";  
     }  
     return details;  
   }  
   public int getId()  
   {  
     return Id;  
   }  
   public String getDescription()  
   {  
     return description;  
   }  
   public Bid getHighestBid()  
   {  
     return highestBid;  
   }  
 }  


Bid

 /**  
  * class Bid  
  *  
  * @author (Ismail)  
  * @version (09102018)  
  */  
 public class Bid  
 {  
   private final Person bidder;  
   private final long value;  
   public Bid(Person bidder, long value)  
   {  
     this.bidder = bidder;  
     this.value = value;  
   }  
   public Person getBidder()  
   {  
     return bidder;  
   }  
   public long getBid()  
   {  
     return value;  
   }  
 }  

EAS PBO B

1. Rancangan interface image editor. 2. Class diagram dari image editor yang akan dibuat terdiri atas 10 class seperti berikut. ...