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;  
   }  
 }  

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

Tidak ada komentar:

Posting Komentar