TUGAS  PEMROGRAMAN BERORIENTASI OBJEK kelas b

aUCTION DAN MUSIC


ZAHRUL ZIZKI DINANTO
05111740000168
PBO B


AUCTION :



SOURCE CODE :
AUCTION
 import java.util.ArrayList;   
  /**   
  * A simple model of an auction   
  *The auction mantains a list of lots of arbitatry length   
  * @author Zahrul Zizki D 05111740000168  
  * @version 10.0/20181008   
  */   
public class Auction   
  {   
   private ArrayList<Lot> lots;  
   private int LotNumber;   
   public Auction()  
   {   
    lots = new ArrayList<Lot>();  
 
    LotNumber = 1;  
   }   
   public void enterLot(String description)   
   {   
    lots.add(new Lot(LotNumber, description));   
    LotNumber++;   
   }   
   public void showLots()   
   {  
    for(Lot lot : lots) {   
     System.out.println(lot.detail());   
    }   
   }   
   public void MakeBid(int CurrentlotNumber, Person bidder, long value)   
   {   
    Lot selectedLot = getLot(CurrentlotNumber);   
    if(selectedLot != null) {   
     boolean check = selectedLot.bidFor(new Bid(bidder, value));   
     if(check) {    
      System.out.println("Bid  lot nomor " +   
           CurrentlotNumber + " berhasil dilakukan");  
      System.out.println("Bid dilakukan oleh " +bidder.getName()+ " Dengan Harga " +value+ "$");   
     }   
     else {   
      Bid highestBid = selectedLot.getHighestBid();   
      System.out.println("Lot nomor : " + CurrentlotNumber +   
           " dengan bid tertinggi: " +   
           highestBid.getBid());   
     }   
    }   
   }   
   /**   
   * Return id lot jika ada, jika tidak return null   
   * CurrentlotNumber = id lot yang perlu di return   
   */   
   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 nomor " +   
           selectedLot.getId() +   
           "telah dikembalikan, bukan lot nomor " +   
           CurrentlotNumber);   
      selectedLot = null;   
     }   
     return selectedLot;   
    }   
    else {   
     System.out.println("Lot nomor : " + CurrentlotNumber +   
          " tidak ada.");   
     return null;   
    }   
   }   
   public void close()    
   {    
   System.out.println("Lelang Selesai.");    
   for(Lot lot : lots)    
   {    
    System.out.println(lot.getId() + ": " +lot.getDescription());    
    Bid bid = lot.getHighestBid();    
    if (bid==null)    
    {    
    System.out.println("Tidak ada bid Pada lot ini");    
    }    
    else    
    {    
    System.out.println(" terjual pada" +    
    bid.getBidder().getName() + " dengan harga : "    
    + bid.getBid());    
    }    
   }    
   }    
  }   


Person
 public class Person   
  {   
   private final String name;   
   public Person(String newName)   
   {  
    this.name = newName;   
   }   
   public String getName()   
   {  
    return name;   
   }   
  }   

Lot

  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 dengan harga " +    
        highestBid.getBid();   
    }   
    else {   
     details += " (belum ada bid)";   
    }   
    return details;   
   }   
   public int getId()   
   {
    return Id;   
   }   
   public String getDescription()   
   {  
    return description;   
   }   
   public Bid getHighestBid()   
   {  
    return highestBid;   
   }   
  }  

Bid



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


SS :






MUSICORGANIZER:



Source Code :


 import java.util.ArrayList;  
 /**  
  * A class to hold details of audio files.  
  *  
  * @author Zahrul Zizki Dinanto
  * @version 13.0/20181008  
  */  
 public class MusicOrganizer  
 {  
   // An ArrayList for storing the file names of music files.  
   private ArrayList<String> files;  

   public MusicOrganizer()  
   {  
     files = new ArrayList<>();  
   }  
 
   public void addFile(String filename)  
   {  
     files.add(filename);  
   }  
    
   public int getNumberOfFiles()  
   {  
     return files.size();  
   }  
    
   public void StartPlaying(int index)  
   {  
     if(index >= 0 && index < files.size()) {  
       String filename = files.get(index);  
       System.out.println("Now Playing : ");  
       System.out.println(filename);  
     }  
   }  
   
   public void removeFile(int index)  
   {  
     if(index >= 0 && index < files.size()) {  
       files.remove(index);  
     }  
   }  
   public void StopPlaying(){  
     System.out.println("----Music Stopped----");  
   }  
 }  

SS :






Komentar

Postingan populer dari blog ini

PBO-B fox and rabbit