Sunday, October 14, 2018

ETS: Membuat Karcis Parkir Elektronik


Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A

Ini adalah ETS untuk membuat Karcis Parkir Elektronik menggunakan Java

Berikut adalah class dan source codenya:

A) Main
 public class Main  
 {  
   public static void main(String args[])  
   {  
     ParkingMachine mesinparkir = new ParkingMachine();  
     mesinparkir.run();  
   }  
 }  

B) ParkingMachine
/**
 * Write a description of class ParkingMachine here.
 *
 * @author Muhammad Naufal Refadi
 * @version 15-10-2018
 */
public class ParkingMachine
{
    private Database database;
    private Keypad keypad;
    private Karcis karcis;
    private Display display;
    private Jenis jenis;
    public ParkingMachine()
    {
        jenis = new Jenis(); 
        database = new Database();
        keypad = new Keypad();
        display = new Display();
    }
    
    public void run()
    {
        while(true)
        {
        
            display.screenMessage("Pilih Jenis Parkir");
            display.screenMessage("1. Mobil");
            display.screenMessage("2. Sepeda Motor");
            int accjenis=keypad.getInput();
            int cost=jenis.cekJenis(accjenis);
            String type=jenis.cekKendaraan(cost);
            display.screenMessage("Masukkan plat nomor kendaraan anda");
            String platnomor=keypad.getInputString();
            display.screenMessage("Tempelkan kartu anda");
            int cekNum = keypad.getInput();
            if(database.cekUser(cekNum))
            {
                if(database.getAccountBalance(database.cekAccount(cekNum)) >= cost)
                {
                    database.pay(database.cekAccount(cekNum), cost);
                    karcis = new Karcis(database.cekAccount(cekNum).getBalance(),cost,platnomor,type);
                    karcis.print();
                    display.screenMessage("Silahkan mengambil karcisnya");
                    display.screenMessage("Berikan 1 karcis kepada jukir dan simpan 1 karcisnya");
                    display.screenMessage("Terima kasih telah menggunakan layakan kami\n");
                    
                }
                else
                {
                    display.screenMessage("Sisa Saldo anda tidak mencukupi\n");
                }
            }
            else
            {
                display.screenMessage("Nomor Kartu anda tidak ditemukan. Silahkan ulangi sekali lagi\n");
            }
    }
    
 }
}

c) Jenis
public class Jenis
{  
    public int cekJenis(int jenis)
    {
        int harga=0;
        if(jenis==1){harga=3000;}
        else if(jenis==2){harga=2000;}
        return harga;
    }
    public String cekKendaraan(int price)
    {    String trans="";
        if(price==3000){ trans="MOBIL";}
        else if(price==2000){trans="Sepeda Motor";}
        return trans;
    }
   
}

d) Database
 public class Database  
 {    
   private Account accounts[];  
   public Database()  
   {  
     accounts = new Account[7];  
     accounts[0] = new Account(38321,32000);  
     accounts[1] = new Account(94821,103000);  
     accounts[2] = new Account(19230,100000);  
     accounts[3] = new Account(49234, 40500);  
     accounts[4] = new Account(82019, 55000);  
     accounts[5] = new Account(59120, 89000);  
     accounts[6] = new Account(45352, 70000);  
   }  
   public Account cekAccount(int AccountNumber)  
   {  
     for(Account currentAccount : accounts)  
     {  
       if ( currentAccount.getAccountNumber() == AccountNumber ) return currentAccount;  
     }  
     return null;  
   }  
   public boolean cekUser(int UserAccount)  
   {  
     Account userAccount = cekAccount(UserAccount);  
     if(userAccount == null){return false;}  
     return true;  
   }  
   public int getAccountBalance(Account useraccount)  
   {  
     return useraccount.getBalance();  
   }  
   public void pay(Account useraccount, int amount)  
   {  
     useraccount.pay(amount);  
   }  
 }  
e) Account
 public class Account  
 {  
   private int accountNumber;  
   private int balance;  
   public Account(int AccountNumber, int Balance)  
   {  
     accountNumber = AccountNumber;  
     balance = Balance;  
   }  
   public int getBalance()  
   {  
     return balance;  
   }  
   public int getAccountNumber()  
   {  
     return accountNumber;  
   }  
   public void pay(int Cost)  
   {  
     balance = balance - Cost;  
   }  
 }  

f) Display
 public class Display  
 {  
   public void screenMessage(String message)  
   {   
     System.out.println(message);   
   }  
 }  

g) Keypad
 import java.util.Scanner;  
 public class Keypad  
 {  
   private Scanner input;  
   public Keypad()  
   {   
     input = new Scanner(System.in);   
   }  
   public int getInput()  
   {   
     return input.nextInt();   
   }  
   public String getInputString()   
   {   
    Scanner sc = new Scanner(System.in);   
    String input = sc.nextLine();   
    return input;   
   }   
 }   
h) Karcis
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class Karcis
{
    int balance;
    int price;
    String plat;
    String transp;
    private Date date;
    private DateFormat dateFormat;
    public Karcis(int Balance, int Price,String Plat,String Transp)
    {
        balance = Balance;
        price = Price;
        plat=Plat;
        transp=Transp;
        dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        date = new Date();
    }
    public void print()
    {
        System.out.println("###############################################");
        System.out.println("#KOTA SURABAYA                                #");
        System.out.println("#Parkir ELektronik Taman Bungkul              #");
        System.out.println("#Jenis Kendaraan: " +transp+"                       #");
        System.out.println("#Plat Nomor: " +plat+"                        #");
        System.out.println("#Tanggal Transaksi: " + dateFormat.format(date)+"       #");
        System.out.println("#Biaya Parkir: " + price+"                           #");
        System.out.println("#Sisa Saldo: " + balance+"                            #");
        System.out.println("###############################################");
    }
}

Dan inilah hasil Screenshot Bagan Class


Ini adalah hasil output jika salah membaca no.kartu karena beberapa alasan seperti kartu tidak terdaftar.








Sunday, October 7, 2018

PBO A: Membuat Tech Support/Support System

Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A

Ini adalah tugas untuk membuat Tech Support/Support System

a) SupportSystem
  /**   
  * Tech Support   
  * @author Muhammad Naufal Refadi   
  * @version 8 October 2018   
  */   
 import java.util.HashSet;  
 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){  
       HashSet<String> input=reader.getInput();  
       if(input.contains("bye")){  
         finished=true;  
       }  
       else{  
         String response=responder.generateResponse();  
         System.out.println(response);  
       }  
     }  
     printGoodbye();  
   }      
   private void printWelcome()  
     {  
      System.out.println("Welcome to the DodgySoft Technical Support System.");  
      System.out.println();  
      System.out.println("Please tell us about your problem.");  
      System.out.println(  
      "We will assist you with any problem you might have.");  
      System.out.println(  
      "Please type 'bye' to exit our system.");  
     }  
   /**  
   * Print a good-bye message to the screen.   
   */  
   private void printGoodbye()  
   {  
     System.out.println("Nice talking to you. Bye...");  
   }  
 }  

b) InputReader
 import java.util.HashSet;  
 import java.util.Scanner;  
 /**  
  * InputReader reads typed text input from the standard text terminal.   
  * The text typed by a user is then chopped into words, and a set of words   
  * is provided.  
  *   
  * @author   Michael Kolling and David J. Barnes  
  * @version  2008.03.30  
  */  
 public class InputReader  
 {  
   private Scanner reader;  
   /**  
    * Create a new InputReader that reads text from the text terminal.  
    */  
   public InputReader()  
   {  
     reader = new Scanner(System.in);  
   }  
   /**  
    * Read a line of text from standard input (the text terminal),  
    * and return it as a set of words.  
    *  
    * @return A set of Strings, where each String is one of the   
    *     words typed by the user  
    */  
   public HashSet<String> getInput()   
   {  
     System.out.print("> ");        // print prompt  
     String inputLine = reader.nextLine().trim().toLowerCase();  
     String[] wordArray = inputLine.split(" "); // split at spaces  
     // add words from array into hashset   
     HashSet<String> words = new HashSet<String>();  
     for(String word : wordArray) {  
       words.add(word);  
     }  
     return words;  
   }  
 }  

c)Responder
 public class Responder  
 {  
   /**  
     * Create a responder.  
    */  
   public Responder()  
   {  
   }  
   /**  
   * Generate a response.  
   * @return A string that should be displayed as the  
   * response  
   */  
   public String generateResponse()  
   {  
     return "That sounds interesting. Tell me more...";  
   }  
 }  

Berikut hasil screenshot bagan class dan outputnya




Tugas PBO-A: Membuat Auction System (Sistem Lelang)

Nama; Muhammad Naufal Refadi
NRP: 05111740000097
Kelas: PBO-A


Ini adalah tugas rumah saya membuat Auction System atau bisa disebut sistem lelang dengan menggunakan Java.

Berikut Formatted Source code saya:
a) Person
 public class Person   
  {   
   // The name of this person.   
   private final String name;   
   /**   
   * Create a new person with the given name.   
   */   
   public Person(String name)   
   {   
    this.name = name;   
   }   
   /**   
   * @return The Person's name*   
   */   
   public String getName()   
   {   
    return name;   
   }   
  }   

b) Bid
 public class Bid   
  {   
   private final Person bidder;   
   private final long value;   
   /**   
   * Create a 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;   
   }   
  }   

c) Lot
 public class Lot   
  {   
   private final int number;    
   private String description;    
   private Bid highestBid;   
   /**   
    * Construct a Lot, setting its number and description.    
   */   
   public Lot(int number, String description)   
   {   
    this.number = number;   
    this.description = description;   
   }   
   /**   
   * Attempt to bid for this lot. A successful bid   
   * must have a value higher than any existing bid.    
   * @return true if successful, false otherwise.   
   */   
   public boolean bidFor(Bid bid)   
   {   
    if((highestBid == null)||(bid.getValue() &gt; highestBid.getValue()))   
    {   
     highestBid = bid;   
     return true;   
    }   
    else{   
     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;   
   }    
   public String getDescription()   
   {   
    return description;   
   }   
   public Bid getHighestBid()   
   {   
    return highestBid;   
   }   
  }   

d)Auction
 /**  
  * Auction Systems  
  * @author Muhammad Naufal Refadi  
  * @version 7 October 2018  
  */  
 import java.util.ArrayList;   
  public class Auction   
  {    
   private ArrayList<Lot> lots;    
   private int nextLotNumber;    
   public Auction()   
   {   
    lots = new ArrayList<Lot>();   
    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)   
    {   
     boolean succesful = selectedLot.bidFor(new Bid(bidder, value));   
     if (succesful)   
     {   
      System.out.println("The bid for lot number " + lotNumber + " was succesful.");   
     }   
     else   
     {    
      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))   
    {   
     Lot selectedLot = lots.get(lotNumber-1);   
     if (selectedLot.getNumber() != lotNumber)   
     {   
      System.out.println("Internal error: Lot number " + selectedLot.getNumber() + " was returned instead of " + lotNumber);   
      selectedLot = null;   
     }   
     return selectedLot;   
    }   
    else   
    {   
     System.out.println("Lot number: " + lotNumber + " does not exist.");   
     return null;   
    }   
   }   
   public void close()   
   {   
    System.out.println("Closing auction.");   
    for (Lot lot : lots)   
    {   
     System.out.println(lot.getNumber() + ": " + lot.getDescription());   
     if (lot.getHighestBid() == null)   
     {   
      System.out.println (" (No bids) ");   
     }   
     else   
     {   
      Bid highestBid = lot.getHighestBid();   
      System.out.println(" sold to " + highestBid.getBidder().getName() + " for " + highestBid.getValue());   
     }   
    }   
   }   
  }   

Screenshot jalannya dan output program

Pertama klik class person dan klik newperson() untuk membuat nama siapa aja yang akan mengikuti acara lelang. Anggap saja nama orangnya orang1,orang2, dan orang 3


Lalu klik class auction dan klik enterslot() untuk memasukkan nama orang untuk mengikut acara lelang.

lalu klik void makeABid()(untuk memberikan tawaran seharga yang diinput



Jika kita ingin melihat hasil tawaran sementara bisa menggunakan void showLots() 

klik void close() untuk menutup lelangan dan mengeluarkan hasil akhirnya