Minggu, 14 Oktober 2018

Nama : Chaniyah Zulfa Mukhlishah
Kelas :PBO-B

                                                                 ETS PBO-B

 Ets kali ini membuat tiket parkir elektronik atau manless. Saya menggunakan 2 class yaitu




1. Class Main
2. Class Ticket
.
Untuk source code class main =


 /**  
  * Source code class main  
  *  
  * @author (Chaniyah Zulfa Mukhlishah)  
  * @version (15/10/2018)  
  */  
  import java.util.Scanner;   
  public class main   
  {   
   public static void main(String args[])   
   {   
    Scanner scan = new Scanner(System.in);   
    int vehicle,saldo,lama_parkir;   
    String plat;   
    System.out.println("Welcome to parking area");   
    System.out.println("-------------------------------");   
    System.out.println("Pilih Kendaraan: ");   
    System.out.println("1. Motor");   
    System.out.println("2. Mobil");  
    System.out.print("Kendaraan yang diparkir: ");   
    vehicle = scan.nextInt();  
    Ticket tick= new Ticket(vehicle);  
    System.out.print("Masukkan nomor plat anda : ");   
    plat = scan.next();   
    tick.masukkan_plat(plat);  
    System.out.print("Masukkan lama waktu parkir (dalam jam): ");   
    lama_parkir = scan.nextInt();   
    tick.masukkan_durasi(lama_parkir);  
    System.out.print("Masukkan saldo anda: Rp ");   
    saldo = scan.nextInt();   
    tick.masukkan_saldo(saldo);  
    System.out.println("--------------------------------------");  
    if(vehicle == 1)  
   {   
    System.out.println("Kendaraan yang anda parkir adalah Motor");  
    System.out.println("Tarif : Rp 3000/jam. Tarif yang anda bayar: Rp " + lama_parkir*3000);   
   }  
    else if(vehicle == 2)  
   {  
    System.out.println("Kendaraan yang anda parkir adalah Mobil");  
    System.out.println("Tarif : Rp 5000/jam. Tarif yang anda bayar: Rp " + lama_parkir*5000);   
   }   
    System.out.println("Ketik '0' untuk mencetak karcis");   
    int perintah = scan.nextInt();  
    if(perintah== 0)  
     {tick.printTicket();}   
   }     
  }   
.
Untuk source code class ticket :
 /**  
  * Source code class Ticket  
  *  
  * @author (Chaniyah Zulfa Mukhlishah)  
  * @version (15/10/2018)  
  */  
 public class Ticket   
  {    
   private int hargamotor = 3000;   
   private int hargamobil = 5000;  
   private int lama_parkir;  
   private int saldo;  
   private String plat;   
   private int vehicle;   
   public Ticket(int jenis)   
   {   
    vehicle = jenis;    
   }   
   public void masukkan_saldo(int uang)   
   {   
     saldo = uang;  
   }   
   public void masukkan_durasi(int time)   
   {   
    lama_parkir = time;   
   }   
   public void masukkan_plat(String no)   
   {   
    plat = no;   
   }   
   public void printTicket() //1=motor, 2=mobil   
   {   
    if(vehicle == 1)   
    {   
     if (saldo > 0)   
     {   
      if (saldo >= hargamotor*lama_parkir)   
      {   
       System.out.println('\u000C');   
       System.out.println("KARTU PEMBAYARAN PARKIR");   
       System.out.println("===============================");   
       System.out.println("Durasi parkir: " + lama_parkir + " jam");   
       System.out.println("Kendaraan: Motor");   
       System.out.println("Plat nomor: " + plat);    
       System.out.println("Tarif: Rp " + hargamotor*lama_parkir);   
       int kembalian_mot = saldo - hargamotor*lama_parkir;   
       System.out.println("Kembalian saldo anda: Rp " + kembalian_mot);   
      }  
      else   
      {   
       System.out.println("Saldo anda tidak mencukupi, isi saldo terlebih dahulu, atau jangan parkir sini ya");   
      }   
     }   
    }   
    else if(vehicle == 2)   
    {   
     if (saldo > 0)   
     {   
      if (saldo >= hargamobil*lama_parkir)   
      {   
       System.out.println('\u000C');   
       System.out.println("KARTU PEMBAYARAN PARKIR");   
       System.out.println("===============================");   
       System.out.println("Durasi parkir: " + lama_parkir + " jam");   
       System.out.println("Kendaraan: Mobil");   
       System.out.println("Plat nomor: " + plat);    
       System.out.println("Tarif: Rp " + hargamobil*lama_parkir);   
       int kembalian_mob = saldo - hargamobil*lama_parkir;   
       System.out.println("Kembalian saldo anda: Rp " + kembalian_mob);   
      }  
      else   
      {   
       System.out.println("Saldo anda tidak mencukupi, isi saldo terlebih dahulu, atau jangan parkir sini ya");   
      }   
     }    
    }    
   }    
  }   
.
dan output tampilan awalnya seperti ini =

------------------------------------------------------------------------------

Contoh ketika parkir motor, lalu dicetak =






---------------------------------------------------------------------------------

Contoh ketika parkir mobil, lalu dicetak =



--------------------------------------------------------------------------------------

Contoh ketika saldo tidak cukup =


---------------------------------------------------------------------------------

Sekian, Trimakasih. Semoga Bermanfaat :))

Selasa, 09 Oktober 2018

Music Organizer dan Pelelangan

Nama = Chaniyah Zulfa Mukhlishah
NRP   = 05111740000115
Kelas  = PBO-B

Tugas rumah kali ini adalah membuat Music Organizer untuk mengatur dan memutar lagu, dan satu lagi adalah membuat proses pelelangan.

1. MUSIC ORGANIZER
Pada tugas ini, membutuhkan 2 class, yaitu = Class Music Organizer dan Class Music Player.

--------------------------------------------------------------------------------------------------------------------------

Saat kita menge-Run pada Class Music Organizer, tampilan awal adalah =

--------------------------------------------------------------------------------------------------------------------------

karena belum dibuat playlist, lalu kita membuatnya dengan memilih fungsi 'TambahFile' pada class Music Organizer, dan kita bisa menambahkan lagu/musik yang kita inginkan dengan penambahan awal adalah index ke nol

----(index ke 0)----

----(index ke 1)----

----(index ke 2)----
--------------------------------------------------------------------------------------------------------------------------

Untuk memanggil list yang tersimpan, gunakan fungsi 'listFile' pada class Music Organizer , lalu inputkan index lagu/music


--------------------------------------------------------------------------------------------------------------------------

Untuk menjalankan lagu, gunakan fungsi 'startPlaying' pada class Music Organizer, pilih lagu dengan inputkan nomor/index lagu


--------------------------------------------------------------------------------------------------------------------------

Untuk memberhentikan lagu, gunakan fungsi 'stopPlaying' pada class Music Organizer

--------------------------------------------------------------------------------------------------------------------------

Source Code untuk Class Music Organizer =

 /**  
  * Source Code Class Music Player  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  *//**  
  * Source Code Class Music Player  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  /**  
  * Source Code Class Music Player  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  */  
 import java.util.ArrayList;  
 public class MusicOrganizer  
 {  
   private ArrayList<String> files;  
   private MusicPlayer player;  
   public MusicOrganizer()  
   {  
     files = new ArrayList<>();  
     player = new MusicPlayer();  
   }  
   public void tambahFile(String filename)  
   {  
     files.add(filename);  
   }  
   public int totalFiles()  
   {  
     return files.size();  
   }  
   public void listFile(int index)  
   {  
     if(index >= 0 && index < files.size()) {  
       String filename = files.get(index);  
       System.out.println("Lagu nomor " +index+ " adalah: " +filename);  
     }  
   }  
   public void hapusFile(int index)  
   {  
     if(index >= 0 && index < files.size()) {  
       files.remove(index);  
     }  
   }  
   public void startPlaying(int index)  
   {  
     String filename = files.get(index);  
     player.progressing(filename);  
   }  
   public void stopPlaying()  
   {  
     player.selesai();  
   }  
 }  

Source Code untuk Class Music Player =

 /**  
  * Source Code Class Music Player  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  */  
 public class MusicPlayer  
 {  
   private String song;  
   public MusicPlayer()  
   {  
     System.out.println("Belum ada playlist. Makanya, ayo buat dulu :)");  
   }  
   public void progressing(String namafile)  
   {  
     song = namafile;  
     System.out.println(" Music sedang diputar ");  
     System.out.println(" Playing now = " +song );  
   }  
   public void selesai()  
   {  
     System.out.println(" Music berhenti diputar ");  
   }  
 }  

--------------------------------------------------------------------------------------------------------------------------

2. PELELANGAN
Pada tugas ini, membutuhkan 4 class, yaitu =
  - Lot = Barang yang di perjual belikan
  - Bit = Tawaran
  - Person = SI Penawar


--------------------------------------------------------------------------------------------------------------------------
Input nama barang yang akan dilelang (diperjual belikan) , gunakan fungsi 'enterLot' pada Class Auction


, maka setelah di list akan keluar =

--------------------------------------------------------------------------------------------------------------------------

Masukkan nama penawar pada Class Person


--------------------------------------------------------------------------------------------------------------------------

Lalu, masukkan tawaran dari penawar(oran1 dan orang2) menggunakan fungsi 'makeABid' pada Class Auction

(Number 1 menunjukkan penawaran untuk jenis barang ke 1 yaitu Laptop)
--------------------------------------------------------------------------------------------------------------------------

Pelelangan sukses dan dari 2 penawar akan diambil yang menawar paling mahal, yaitu Chan dengan tawaran = 500366 pada laptop

--------------------------------------------------------------------------------------------------------------------------

Setelah proses selesai, maka pelelnagan ditutup menggunakan fungsi 'close' pada Class Auction, dan akan ditunjukkan hasil akhir dari lelangan.

--------------------------------------------------------------------------------------------------------------------------

Source Code untuk Class Auction =

 import java.util.ArrayList;  
 /**  
  * Pelelangan  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  */  
 public class Auction  
 {  
   private ArrayList<Lot> lots;  
   private int nextLotNumber;  
   public Auction()  
   {  
     lots = new ArrayList<>();  
     nextLotNumber = 1;  
   }  
   public void enterLot(String description)  
   {  
     lots.add(new Lot(nextLotNumber, description));  
     nextLotNumber++;  
   }  
   public void showLots()  
   {  
     for(Lot lot : lots) {  
       System.out.println(lot.toString());  
     }  
   }  
   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("The bid for lot number " +  
                   lotNumber + " was successful.");  
         System.out.println("The bid is especially for " + bidder.getName());  
       }  
       else {  
         // Report which bid is higher.  
         Bid highestBid = selectedLot.getHighestBid();  
         System.out.println("Lot number: " + lotNumber +  
                   " already has a bid of: " +  
                   highestBid.getValue());  
       }  
     }  
   }  
   public Lot getLot(int lotNumber)  
   {  
     if((lotNumber >= 1) && (lotNumber < nextLotNumber)) {  
       // The number seems to be reasonable.  
       Lot selectedLot = lots.get(lotNumber - 1);  
       // Include a confidence check to be sure we have the  
       // right lot.  
       if(selectedLot.getNumber() != lotNumber) {  
         System.out.println("Internal error: Lot number " +  
                   selectedLot.getNumber() +  
                   " was returned instead of " +  
                   lotNumber);  
         // Don't return an invalid lot.  
         selectedLot = null;  
       }  
       return selectedLot;  
     }  
     else {  
       System.out.println("Lot number: " + lotNumber +  
                 " does not exist.");  
       return null;  
     }  
   }  
   public void close(){    
     System.out.println("Auction is closed.");    
     for(Lot lot : lots){    
     System.out.println(lot.getNumber() + ": " + lot.getDescription());    
     Bid bid = lot.getHighestBid();    
     if(bid == null){    
       System.out.println("There are no more Bids for this lot.");    
       }    
       else{    
       System.out.println("This Item has been sold to " + bid.getBidder().getName() + " Price : " + bid.getValue());    
       }    
     }    
   }    
 }  

Source Code untuk Class Lot =


 /**  
  * Source Code Lot  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  **/  
 public class Lot  
 {  
   private final int number;  
   private String description;  
   private Bid highestBid;  
   public Lot(int number, String description)  
   {  
     this.number = number;  
     this.description = description;  
     this.highestBid = null;  
   }  
   public boolean bidFor(Bid bid)  
   {  
     if(highestBid == null) {  
       // There is no previous bid.  
       highestBid = bid;  
       return true;  
     }  
     else if(bid.getValue() > highestBid.getValue()) {  
       // The bid is better than the previous one.  
       highestBid = bid;  
       return true;  
     }  
     else {  
       // The bid is not better.  
       return false;  
     }  
   }  
   public String toString()  
   {  
     String details = number + ": " + description;  
     if(highestBid != null) {  
       details += "  Bid: " +   
             highestBid.getValue();  
     }  
     else {  
       details += "  (No bid)";  
     }  
     return details;  
   }  
   public int getNumber()  
   {  
     return number;  
   }  
   public String getDescription()  
   {  
     return description;  
   }  
   public Bid getHighestBid()  
   {  
     return highestBid;  
   }  
 }  

Source Code untuk Class Lot =

  /**  
  * Source Code Bit  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  **/  
 public class Bid  
 {  
   // The person making the bid.  
   private final Person bidder;  
   // The value of the bid. This could be a large number so  
   // the long type has been used.  
   private final long value;  
   /**  
    * Create a bid.  
    * @param bidder Who is bidding for the lot.  
    * @param value The value of the bid.  
    */  
   public Bid(Person bidder, long value)  
   {  
     this.bidder = bidder;  
     this.value = value;  
   }  
   /**  
    * @return The bidder.  
    */  
   public Person getBidder()  
   {  
     return bidder;  
   }  
   /**  
    * @return The value of the bid.  
    */  
   public long getValue()  
   {  
     return value;  
   }  
 }  

Source Code untuk Class Person =

  /**  
  * Source Code Person  
  * @author Chaniyah Zulfa Mukhlishah  
  * @version 2018.10.09  
  **/  
 public class Person  
 {  
   // The name of this person.  
   private final String name;  
   public Person(String name)  
   {  
     this.name = name;  
   }  
   public String getName()  
   {  
     return name;  
   }  
 }  

--------------------------------------------------------------------------------------------------------------------------