Minggu, 14 Oktober 2018

Sistem Parkir Elektronik

Sistem Parkir Elektronik

Nama  : Timothyus Tanner
NRP    : 05111740000103
Kelas  : PBO - A

Source Code

1. Parkir_Meter

 /**  
  * Sistem Parkir Elektronik  
  *  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 import java.util.Scanner;  
 public class Parkir_Meter  
 {  
   public static void main()  
   {    
     Scanner scan = new Scanner(System.in);  
     System.out.println("Masukkan saldo anda");  
     int saldo = scan.nextInt();  
     System.out.print('\u000C');  
     System.out.println("Pilih Jenis Kendaraan Anda");  
     System.out.println("1. Mobil");  
     System.out.println("2. Motor");  
     int pilih;  
     pilih = scan.nextInt();  
     System.out.print('\u000C');  
     if(pilih == 1)  
     {  
       Mobil mobil = new Mobil();  
       mobil.NomorPlat();  
       System.out.print('\u000C');  
       mobil.print(saldo);  
     }  
     else if(pilih == 2)  
     {  
       Motor motor = new Motor();  
       motor.NomorPlat();  
       System.out.print('\u000C');  
       motor.print(saldo);  
     }  
   }  
 }  

2. Mobil

 /**  
  * Sistem Parkir Elektronik  
  *  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 import java.util.Scanner;  
 public class Mobil  
 {  
   Scanner scan = new Scanner(System.in);  
   String input;  
   int jam, total;  
   public String NomorPlat()  
   {  
     System.out.println("Silahkan Masukkan Nomor Plat Anda");  
     input = scan.nextLine();  
     return input;  
   }  
   public int durasi()  
   {  
     System.out.println("Silahkan masukkan durasi");  
     System.out.println("(Durasi dalam satuan jam)");  
     jam = scan.nextInt();  
     jam = jam / 24 + 1;  
     return jam;  
   }  
   public int jumlah()  
   {  
     total = durasi();  
     System.out.print('\u000C');  
     System.out.println("Tempelkan kartu pembayaran untuk membayar");  
     total = total * 4000;  
     System.out.println("Total Pembayaran : " + total);  
     return total;  
   }  
   public void print(int saldo)  
   {  
     int tot = jumlah();  
     System.out.print('\u000C');  
     System.out.println("Silahkan ambil karcis anda");  
     System.out.println("-------------------------");  
     System.out.println("| Jenis Kendaraan : Mobil");  
     System.out.println("| Nomor Plat : " + input);  
     System.out.println("| Tarif parkir : " + tot);  
     System.out.println("| Sisa Saldo : " + (saldo - tot));  
     System.out.println("-------------------------");  
   }  
 }  

3. Motor

 /**  
  * Sistem Parkir Elektronik  
  *  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 import java.util.Scanner;  
 public class Motor  
 {  
   Scanner scan = new Scanner(System.in);  
   String input;  
   int jam, total;  
   public String NomorPlat()  
   {  
     System.out.println("Silahkan Masukkan Nomor Plat Anda");  
     input = scan.nextLine();  
     return input;  
   }  
   public int durasi()  
   {  
     System.out.println("Silahkan masukkan durasi");  
     System.out.println("(Durasi dalam satuan jam)");  
     jam = scan.nextInt();  
     jam = jam / 24 + 1;  
     return jam;  
   }  
   public int jumlah()  
   {  
     total = durasi();  
     System.out.print('\u000C');  
     System.out.println("Tempelkan kartu pembayaran untuk membayar");  
     total = total * 4000;  
     System.out.println("Total Pembayaran : " + total);  
     return total;  
   }  
   public void print(int saldo)  
   {  
     int tot = jumlah();  
     System.out.print('\u000C');  
     System.out.println("Silahkan ambil karcis anda");  
     System.out.println("-------------------------");  
     System.out.println("| Jenis Kendaraan : Motor");  
     System.out.println("| Nomor Plat : " + input);  
     System.out.println("| Tarif parkir : " + tot);  
     System.out.println("| Sisa Saldo : " + (saldo - tot));  
     System.out.println("-------------------------");  
   }  
 }  


Screenshoot







Senin, 08 Oktober 2018

Support System

Support System

Nama  : Timothyus Tanner
NRP    : 05111740000103
Kelas   : PBO - A

Source Code

1. Support System

 /**  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *  
  */  
  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("metu")){   
      finished = true;   
     }   
     else{   
      String response = responder.generateResponse();   
      System.out.println(response);   
     }   
    }   
    printGoodbye();   
   }   
   private void printWelcome(){   
    System.out.println("Selamat Datang");   
    System.out.println("Ngetik o sesuatu");   
    System.out.println("tulis 'metu' gawe metu tutuk kene");   
   }   
   private void printGoodbye(){   
    System.out.println("Bye bye :P");   
   }   
  }   

2. InputReader

 /**  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *  
  */  
  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;   
   }   
  }   

3. Responder

 /**  
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *  
  */  
 public class Responder   
  {   
   public Responder(){   
   }   
   public String generateResponse(){   
    return "Timo Ganteng";    
   }   
  }   

Screenshoot


Minggu, 07 Oktober 2018

AUCTION

AUCTION

Nama  : Timothyus Tanner
NRP    : 05111740000103
Kelas  : PBO - A

Source Code
1. Auction

 /**   
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *   
  */  
 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());    
    }    
   }    
   }    
 }    

2. Lots

 /**   
  * Nama : Timothyus Tanner   
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  *   
  */   
  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;    
   }    
  }    

3. Bid

 /**   
  * Nama : Timothyus Tanner   
  * NRP  : 05111740000103   
  * Kelas : PBO - A  
  */   
 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;    
   }    
  }    

4. Person

 /**    
  * Nama : Timothyus Tanner  
  * NRP  : 05111740000103  
  * Kelas : PBO - A  
  */  
 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;    
   }    
 }    

Screenshoot