Minggu, 14 Oktober 2018

PBO B

Hari ini UTS pbo kelas B tentang manless ticket park system

Manless Parking System adalah sistem Parkir yang di pintu masuknya tidak dijaga oleh operator. Namun digantikan oleh kotak dispenser yang ada tombolnya untuk membuka palang parkir dan mencetak tanda mulai parkir. Sistem Parkir seperti ini banyak digunakan di bandara, Rumah Sakit,  Gedung Perkantoran,  Aparartment, Mall-Plaza  dan lain sebagainya.



     1.Class


















     2.Parking


 /**  
  * main Parking  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (15/10/2018)  
  */  
 import java.util.Scanner;  
 public class Parking {  
   public static void main(String[] args) {  
     Scanner scan= new Scanner(System.in);  
     System.out.println("Press any to continue \n");  
     int x,menu;  
     menu =0;  
     menu=scan.nextInt();  
       if(menu==1){  
       Ticket ticket = new Ticket("1", 2500, "RP", "2018-05-26 14:53:18", "2018-05-26 15:53:18", "KR123XC");       
       ticket.printTicketInfo();   
       }  
       else if(menu==2){  
       Ticket ticket1 = new Ticket("2", 2500, "RP", "2018-05-27 15:56:17", "2018-05-23 15:53:18", "ODIREXC");  
       ticket1.printTicketInfo();  
       } else if(menu==3){  
       Ticket ticket2 = new Ticket("3", 2500, "RP", "2018-05-10 10:50:10", "2018-05-20 10:50:10", "DKOEDXC");  
       ticket2.printTicketInfo();  
       } else if(menu==4){  
       Ticket ticket3 = new Ticket("4", 2500, "RP", "2018-05-22 15:50:10", "2018-05-25 20:50:10", "DKENFXC");  
       ticket3.printTicketInfo();   
       } else if(menu==5){  
       Ticket ticket4 = new Ticket("5", 2500, "RP", "2018-05-18 15:52:13", "2018-03-23 11:53:18", "SKEODXC");  
       ticket4.printTicketInfo();  
       } else {  
       Ticket ticket5 = new Ticket("6", 2500, "RP", "2018-05-23 13:45:18", "2018-06-22 12:50:10", "2SODEXC");  
       ticket5.printTicketInfo();  
       }  
   }   
 }  

     3.Ticket


 /**  
  * main ticket  
  *  
  * @author (Chrisnady Anggaiswara)  
  * @version (15/10/2018)  
  */  
 public class Ticket {  
   private static int count = 0;  
   private boolean isFilled;  
   private String ticketId;  
   private int ticketPrice;  
   private String currency;  
   private String dateOfPurchase;  
   private String expirationDate;  
   private String vehicleRegistrationNumber;  
   private final String emergencyPhoneNumber = "123456789";  
   //Constructors  
   public Ticket(String ticketId, int ticketPrice, String currency, String dateOfPurchase, String expirationDate, String vehicleRegistrationNumber) {  
     this.setTicketId(ticketId);  
     this.setTicketPrice(ticketPrice);  
     this.setCurrency(currency);  
     this.setDateOfPurchase(dateOfPurchase);  
     this.setExpirationDate(expirationDate );  
     this.setVehicleRegistrationNumber(vehicleRegistrationNumber);  
   }  
   //Getters and Setters  
   public String getTicketId() {  
     return ticketId;  
   }  
   public void setTicketId(String ticketId) {  
     this.ticketId = ticketId;  
   }  
   public int getTicketPrice() {  
     return ticketPrice;  
   }  
   public void setTicketPrice(int ticketPrice) {  
     this.ticketPrice = ticketPrice;  
   }  
   public String getCurrency() {  
     return currency;  
   }  
   public void setCurrency(String currency) {  
     this.currency = currency;  
   }  
   public String getDateOfPurchase() {  
     return dateOfPurchase;  
   }  
   public void setDateOfPurchase(String dateOfPurchase) {  
     this.dateOfPurchase = dateOfPurchase;  
   }  
   public String getExpirationDate() {  
     return expirationDate;  
   }  
   public void setExpirationDate(String expirationDate) {  
     int a = 0;  
     a = a+1;  
     this.expirationDate = expirationDate+a;  
   }  
   private String getVehicleRegistrationNumber() {  
     return vehicleRegistrationNumber;  
   }  
   private void setVehicleRegistrationNumber(String vehicleRegistrationNumber) {  
     this.vehicleRegistrationNumber = vehicleRegistrationNumber;  
   }  
   private String getEmergencyPhoneNumber() {  
     return emergencyPhoneNumber;  
   }  
   //Method to print information about ticket  
   public void printTicketInfo() {  
     System.out.println("########################################");  
     System.out.println("########################################");  
     System.out.println("########################################");  
     String ticketInformation = "  Ticket ID: " + getTicketId() + "\n" +  
         "  Ticket price: " + getTicketPrice() + getCurrency() + "\n" +  
         "  Purchase date: " + getDateOfPurchase() + "\n" +  
         "  Expiration date: " + getExpirationDate() + "\n" +  
         "  Vehicle registration number: " + getVehicleRegistrationNumber() + "\n" +  
         "  Emergency phone number: " + getEmergencyPhoneNumber();  
     System.out.println(ticketInformation);  
     System.out.println("########################################");  
     System.out.println("########################################");  
     System.out.println("########################################");  
   }  
 }  

     4.Hasil

Selasa, 09 Oktober 2018

PBO B


Pada kesempatan kali ini, Kita diajarkan membuat pemutar musik dan pelelangan menggunakan BlueJ
Chrisnady Anggaiswara
5111640000153
Berikut hasilnya.


     1. Musik Organizer



  import java.util.ArrayList;   
  /**   
  * A class to hold details of audio files.   
  *   
  * @author Chrisnady Anggaiswara  
  * @version 13.0/20181009   
  */   
  public class MusicOrganizer   
  {   
   // An ArrayList for storing the file names of music files.   
   private ArrayList<String> files;   
   /**   
   * Create a MusicOrganizer   
   */   
   public MusicOrganizer()   
   {   
    files = new ArrayList<>();   
   }   
   /**   
   * Add a file to the collection.   
   * @param filename The file to be added.   
   */   
   public void addFile(String filename)   
   {   
    files.add(filename);   
   }   
   /**   
   * Return the number of files in the collection.   
   * @return The number of files in the collection.   
   */   
   public int getNumberOfFiles()   
   {   
    return files.size();   
   }   
   /**   
   * List a file from the collection.   
   * @param index The index of the file to be listed.   
   */   
   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);   
    }   
   }   
   /**   
   * Remove a file from the collection.   
   * @param index The index of the file to be removed.   
   */   
   public void removeFile(int index)   
   {   
    if(index >= 0 && index < files.size()) {   
     files.remove(index);   
    }   
   }   
   public void StopPlaying(){   
    System.out.println("==============================");   
    System.out.println("Music Has Stopped");   
    System.out.println("==============================");   
   }   
  }   

     2.Hasil Musik organizer



















     3.Auction

























 import java.util.ArrayList;  
 /**  
  * A simple model of an auction.  
  * The auction maintains a list of lots of arbitrary length.  
  *  
  * @author Chrisnady Anggaiswara.  
  * @version 2018.10.09  
  */  
 public class Auction  
 {  
   // The list of Lots in this auction.  
   private ArrayList<Lot> lots;  
   // The number that will be given to the next lot entered  
   // into this auction.  
   private int nextLotNumber;  
   /**  
    * Create a new auction.  
    */  
   public Auction()  
   {  
     lots = new ArrayList<>();  
     nextLotNumber = 1;  
   }  
   /**  
    * Enter a new lot into the auction.  
    * @param description A description of the lot.  
    */  
   public void enterLot(String description)  
   {  
     lots.add(new Lot(nextLotNumber, description));  
     nextLotNumber++;  
   }  
   /**  
    * Show the full list of lots in this auction.  
    */  
   public void showLots()  
   {  
     for(Lot lot : lots) {  
       System.out.println(lot.toString());  
     }  
   }  
   /**  
    * Make a bid for a lot.  
    * A message is printed indicating whether the bid is  
    * successful or not.  
    *   
    * @param lotNumber The lot being bid for.  
    * @param bidder The person bidding for the lot.  
    * @param value The value of the bid.  
    */  
   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.");  
       }  
       else {  
         // Report which bid is higher.  
         Bid highestBid = selectedLot.getHighestBid();  
         System.out.println("Lot number: " + lotNumber +  
                   " already has a bid of: " +  
                   highestBid.getValue());  
       }  
     }  
   }  
   /**  
    * Return the lot with the given number. Return null  
    * if a lot with this number does not exist.  
    * @param lotNumber The number of the lot to return.  
    */  
   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;  
     }  
   }  
 }  

     4. Lot Class


 /**  
  * A class to model an item (or set of items) in an  
  * auction: a lot.  
  *   
  * @author Chrisnady Anggaiswara.  
  * @version 2018.10.09  
  */  
 public class Lot  
 {  
   // A unique identifying number.  
   private final int number;  
   // A description of the lot.  
   private String description;  
   // The current highest bid for this lot.  
   private Bid highestBid;  
   /**  
    * Construct a Lot, setting its number and description.  
    * @param number The lot number.  
    * @param description A description of this lot.  
    */  
   public Lot(int number, String description)  
   {  
     this.number = number;  
     this.description = description;  
     this.highestBid = null;  
   }  
   /**  
    * Attempt to bid for this lot. A successful bid  
    * must have a value higher than any existing bid.  
    * @param bid A new bid.  
    * @return true if successful, false otherwise  
    */  
   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;  
     }  
   }  
   /**  
    * @return A string representation of this lot's details.  
    */  
   public String toString()  
   {  
     String details = number + ": " + description;  
     if(highestBid != null) {  
       details += "  Bid: " +   
             highestBid.getValue();  
     }  
     else {  
       details += "  (No bid)";  
     }  
     return details;  
   }  
   /**  
    * @return The lot's number.  
    */  
   public int getNumber()  
   {  
     return number;  
   }  
   /**  
    * @return The lot's description.  
    */  
   public String getDescription()  
   {  
     return description;  
   }  
   /**  
    * @return The highest bid for this lot.  
    *     This could be null if there is  
    *     no current bid.  
    */  
   public Bid getHighestBid()  
   {  
     return highestBid;  
   }  
 }  

     5. Bid Class


 /**  
  * A class that models an auction bid.  
  * It contains a reference to the Person bidding and the amount bid.  
  *   
  * @author Chrisnady Anggaiswara.  
  * @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;  
   }  
 }  

     6.Person Class

 /**  
  * Maintain details of someone who participates in an auction.  
  * @author Chrisnady Anggaiswara.  
  * @version 2018.10.09  
  */  
 public class Person  
 {  
   // The name of this person.  
   private final String name;  
   /**  
    * Create a new person with the given name.  
    * @param name The person's name.  
    */  
   public Person(String name)  
   {  
     this.name = name;  
   }  
   /**  
    * @return The person's name.  
    */  
   public String getName()  
   {  
     return name;  
   }  
 }  

     7.  Hasil Auction