Minggu, 14 Oktober 2018

UTS

Source Code
1. Reader

 public class Reader   
  {   
   private InputReader reader;   
   public int kendaraan = 0;   
   public int durasi = 0;   
   public String nopol;   
   public void createReader(){   
    reader = new InputReader();   
    kendaraan = getKendaraan();   
    nopol = getNopol();   
    durasi = getDurasi();   
   }   
   public int getKendaraan(){   
     System.out.println ("===========================================");  
     System.out.println ("===========================================");  
     System.out.println ("   Selamat Datang di Taman Bungkul   ");  
     System.out.println ("  Silahkan Masukkan Jenis Kendaraan Anda ");  
     System.out.println ("         1. Mobil         ");  
     System.out.println ("         2. Motor         ");  
     System.out.println ("===========================================");  
     System.out.println ("===========================================");   
     int kendaraan = reader.getInt();   
    return kendaraan;   
   }   
   public String getNopol(){   
     System.out.println ("===========================================");  
     System.out.println ("===========================================");  
     System.out.println ("  Silahkan Masukkan Nopol Kendaraan Anda ");  
     System.out.println ("===========================================");  
     System.out.println ("===========================================");  
    String nopol = reader.getInput();   
    return nopol;   
   }   
   public int getDurasi(){   
     System.out.println ("===========================================");  
     System.out.println ("===========================================");  
     System.out.println ("  Silahkan Masukkan Durasi Parkir Anda  ");  
     System.out.println ("===========================================");  
     System.out.println ("===========================================");   
     int durasi = reader.getInt();   
    return durasi;   
   }   
  }   

2.Input Reader
  import java.util.Scanner;   
   public class InputReader   
  {   
   public String getInput()   
   {   
    Scanner sc = new Scanner(System.in);   
    String input = sc.nextLine();   
    return input;   
   }   
   public int getInt(){   
    Scanner sc = new Scanner(System.in);   
    int input = sc.nextInt();   
    return input;   
   }   
  }   

3. Tiket

 /**  
  * Jenis Kendaraan  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
 import java.util.Scanner;  
 public class Ticketing   
  {   
   private InputReader input;   
   private Reader reader;   
   private int biaya = 0;   
   public Ticketing()   
   {   
    input = new InputReader();   
    reader = new Reader();   
   }   
  public void printTicket(){   
    System.out.println("####################Tiket1#####################");   
    System.out.println("Jenis kendaraan : " + reader.kendaraan);   
    System.out.println("Nomor polisi : " + reader.nopol);   
    System.out.println("Durasi   : " + reader.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp 3000" );    
    System.out.println("##############################################");   
    System.out.println();   
    System.out.println("####################Tiket2#####################");   
    System.out.println("Jenis kendaraan : " + reader.kendaraan);   
    System.out.println("Nomor polisi : " + reader.nopol);   
    System.out.println("Durasi   : " + reader.durasi + "jam");   
    System.out.println("Biaya Parkir : Rp 3000" );    
    System.out.println("##############################################");   
    System.out.println();   
   } }  

Output

Minggu, 07 Oktober 2018

Support System

08 Oktober 2018

Support System

1. Source Code

a) Support System
 /**  
  * Suport System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
  public class SupportSystem   
  {   
   private InputReader reader;   
   private Responder responder;   
   public SupportSystem(){   
    reader = new InputReader();   
    responder = new Responder();   
   }   
   public void start(){   
    boolean finished = false;   
    printWelcome();   
    while(!finished){   
     String input = reader.getInput();   
     if(input.startsWith("bye")){   
      finished = true;   
     }   
     else{   
      String response = responder.generateResponse();   
      System.out.println(response);   
     }   
    }   
    printGoodbye();   
   }   
   private void printWelcome(){   
    System.out.println("Welcome");   
    System.out.println("Tell me about something");   
    System.out.println("type 'bye' to leave me");   
   }   
   private void printGoodbye(){   
    System.out.println("See ya :)");   
   }   
  }   

b) Input Reader
 /**  
  * Suport System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
  import java.util.Scanner;   
  public class InputReader   
  {   
   public InputReader(){}   
   public String getInput(){   
    String input;   
    Scanner sc = new Scanner(System.in);   
    input = sc.nextLine();   
    sc.close();   
    return input;   
   }   
  }   

c) Responder
 /**  
  * Suport System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
 public class Responder   
  {   
   public Responder(){   
   }   
   public String generateResponse(){   
    return "Hmm";    
   }   
  }   

2. Output


Auction System


08 Okt 2018
AUCTION SYSTEM

1. Source Code

a) Auction
 /**  
  * Auction System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */import java.util.ArrayList;   
  public class Auction   
  {   
   //The list of Lots in this auction.   
   private ArrayList<Lot> lots;   
   //The number that will be given to the nect lot entered into this auction   
   private int nextLotNumber;   
   //Create new auction   
   public Auction(){   
    lots = new ArrayList<Lot>();   
    nextLotNumber = 1;   
   }   
   //Enter a new lot into the auction   
   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.detail());   
    }   
   }   
   //Make a bid for a lot   
   //A message is printed indicating whether the bid is successful or not   
   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 succesdful.");   
      System.out.println("The bid is belong to " + bidder.getName());   
     }   
     else{   
      //Report which bid is higher   
      Bid highestBid = selectedLot.getHighestBid();   
      System.out.println("Lot number " + lotNumber + " already has a bid of " + highestBid.getBid());   
     }   
    }   
   }   
   //Return the lot with the given number.   
   //Return null if a lot with this number does not exist.   
   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.getId() != lotNumber){   
      System.out.println("Internal error: Lot number " + selectedLot.getId() + " was returned instead of " + lotNumber);   
      selectedLot = null;   
     }   
     return selectedLot;   
    }   
    else{   
     System.out.println("Lot number: " + lotNumber + " does not exist.");   
     return null;   
    }   
   }   
   //Close the auction   
   public void close(){   
    System.out.println("Auction is closed.");   
    for(Lot lot : lots){   
     System.out.println(lot.getId() + ": " + 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.getBid());   
     }   
    }   
   }   
  }   

b) Lot
 /**  
  * Auction System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
 public class Lot    
  {    
   // The current highest bid for this lot.   
   private final int id;   
   private String description;   
   private Bid highestBid;   
   //Make a new Lot with id and description   
   public Lot(int numb, String description){   
    this.id = numb;   
    this.description = description;   
   }   
   /**   
   * 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.getBid() > highestBid.getBid()){   
     //The bid is better than the previous one.   
     highestBid = bid;   
     return true;   
    }   
    else{   
     //The bid is not better.   
     return false;   
    }   
   }   
   //To return the lot's id and description   
   public String detail(){   
    String details = id + ":" + description;   
    if(highestBid != null){   
     details += " Bid : " + highestBid.getBid();   
    }   
    else{   
     details += " (No bid)";   
    }   
    return details;   
   }   
   //To return Lot's id   
   public int getId(){   
    return id;   
   }   
   //To return Lot's description   
   public String getDescription(){   
    return description;   
   }   
   //To return the highest bid value   
   public Bid getHighestBid(){   
    return highestBid;   
   }   
  }   

c) Bid
 /**  
  * Auction System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */  
 public class Bid   
  {   
   private final Person bidder;   
   private final long value;   
   //Create new bidder with names and bid value   
   public Bid(Person bidder, long value){   
    this.bidder = bidder;   
    this.value = value;   
   }   
   //To return bidder's name   
   public Person getBidder(){   
    return bidder;   
   }   
   //To return bidder's bid value   
   public long getBid(){   
    return value;   
   }   
  }   

d) Person
 /**  
  * Auction System  
  *  
  * Sherly Rosa Anggraeni  
  * 05111740000018  
  */public class Person   
  {   
   //Create new string for person's name   
   private final String name;   
   public Person(String bidName){   
    this.name = bidName;   
   }   
   //To return person's name   
   public String getName(){   
    return name;   
   }   
  }   

2. Output
- New Auction
- Void enterLot(String description)
- Peson(String BidName)
- Void make a bid