Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Facade Pattern digunakan ketika segmen dari client membutuhkan interface yang sederhana untuk menjalankan semua fungsi dari subsistem yang kompleks.
- // SportCarShop.java
- import java.io.IOException;
- public interface SportCarShop {
- void model() throws NumberFormatException, IOException;
- void productionYear() throws NumberFormatException, IOException;
- void price() throws NumberFormatException, IOException;
- }
- // Lamborghini.java
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Lamborghini implements SportCarShop {
- BufferedReader select = new BufferedReader(new InputStreamReader(System.in));
- private static int choose;
- @Override
- public void model() throws NumberFormatException, IOException {
- System.out.println("\nChoose model do you want :");
- System.out.print("1. Lamborghini Urus"
- + "\n2. Lamborghini Centenario"
- + "\n3. Lamborghini Aventador S Roadster"
- + "\nChoose one : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("You choose Lamborghini Urus");
- }
- break;
- case 2 :
- {
- System.out.print("You choose Lamborghini Centenario");
- }
- break;
- case 3 :
- {
- System.out.print("You choose Lamborghini Aventador S Roadster");
- }
- break;
- default :
- {
- System.out.print("\nSorry, this item is not found.");
- }
- return;
- }
- }
- @Override
- public void productionYear() throws NumberFormatException, IOException {
- System.out.println("\n\nChoose production year do you want : ");
- System.out.print("1. 2015"
- + "\n2. 2016"
- + "\n3. 2017"
- + "\n4. 2018"
- + "\n5. 2019"
- + "\nChoose one : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("You choose 2015");
- }
- break;
- case 2 :
- {
- System.out.print("You choose 2016");
- }
- break;
- case 3 :
- {
- System.out.print("You choose 2017");
- }
- break;
- case 4 :
- {
- System.out.print("You choose 2018");
- }
- break;
- case 5 :
- {
- System.out.print("You choose 2019");
- }
- break;
- default :
- {
- System.out.print("\nSorry, production year is not found.");
- }
- return;
- }
- }
- @Override
- public void price() throws NumberFormatException, IOException {
- System.out.print("\n\nWhat number the type of car you want to buy : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("Rp3.000.000.000\n\n");
- }
- break;
- case 2 :
- {
- System.out.print("Rp25.000.000.000\n\n");
- }
- break;
- case 3 :
- {
- System.out.print("Rp5.000.000.000\n\n");
- }
- break;
- default :
- {
- System.out.print("\nSorry, this item is not found.\n\n");
- }
- return;
- }
- }
- }
- // MercedesBenz.java
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class MercedesBenz implements SportCarShop {
- BufferedReader select = new BufferedReader(new InputStreamReader(System.in));
- private static int choose;
- @Override
- public void model() throws NumberFormatException, IOException {
- System.out.println("\nChoose model do you want :");
- System.out.print("1. Mercedes Benz SL 63 AMG"
- + "\n2. Mercedes Benz AMG GT R"
- + "\n3. Mercedes Benz Maybech S 560"
- + "\nChoose one : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("You choose Mercedes Benz SL 63 AMG");
- }
- break;
- case 2 :
- {
- System.out.print("You choose Mercedes Benz AMG GT R");
- }
- break;
- case 3 :
- {
- System.out.print("You choose Mercedes Benz Maybech S 560");
- }
- break;
- default :
- {
- System.out.print("\nSorry, this item is not found.");
- }
- return;
- }
- }
- @Override
- public void productionYear() throws NumberFormatException, IOException {
- System.out.println("\n\nChoose production year do you want : ");
- System.out.print("1. 2015"
- + "\n2. 2016"
- + "\n3. 2017"
- + "\n4. 2018"
- + "\n5. 2019"
- + "\nChoose one : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("You choose 2015");
- }
- break;
- case 2 :
- {
- System.out.print("You choose 2016");
- }
- break;
- case 3 :
- {
- System.out.print("You choose 2017");
- }
- break;
- case 4 :
- {
- System.out.print("You choose 2018");
- }
- break;
- case 5 :
- {
- System.out.print("You choose 2019");
- }
- break;
- default :
- {
- System.out.print("\nSorry, production year is not found.");
- }
- return;
- }
- }
- @Override
- public void price() throws NumberFormatException, IOException {
- System.out.print("\n\nWhat the type of car you want to buy : ");
- choose = Integer.parseInt(select.readLine());
- switch(choose) {
- case 1 :
- {
- System.out.print("Rp3.400.000.000\n\n");
- }
- break;
- case 2 :
- {
- System.out.print("Rp5.560.000.000\n\n");
- }
- break;
- case 3 :
- {
- System.out.print("Rp7.380.000.000\n\n");
- }
- break;
- default :
- {
- System.out.print("\nSorry, this item is not found.\n\n");
- }
- return;
- }
- }
- }
- // Pay.java
- import java.io.IOException;
- public class Pay {
- private SportCarShop Lamborghini;
- private SportCarShop MercedesBenz;
- public Pay() {
- Lamborghini = new Lamborghini();
- MercedesBenz = new MercedesBenz();
- }
- public void LamborghiniSale() throws NumberFormatException, IOException {
- Lamborghini.model();
- Lamborghini.productionYear();
- Lamborghini.price();
- }
- public void MercedesBenzSale() throws NumberFormatException, IOException {
- MercedesBenz.model();
- MercedesBenz.productionYear();
- MercedesBenz.price();
- }
- }
- // Progress.java
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Progress {
- private static int choice;
- public static void main(String[] args) throws NumberFormatException, IOException {
- do {
- System.out.println("\t\tWELCOME TO SPORT CAR SHOP");
- System.out.print("\n1. Lamborghini"
- + "\n2. Mercedes Benz"
- + "\nEnter Your Choice : ");
- BufferedReader selection = new BufferedReader(new InputStreamReader(System.in));
- choice = Integer.parseInt(selection.readLine());
- Pay car = new Pay();
- switch(choice) {
- case 1 :
- {
- car.LamborghiniSale();
- }
- break;
- case 2 :
- {
- car.MercedesBenzSale();
- }
- break;
- default :
- {
- System.out.println("Nothing you purchased");
- }
- return;
- }
- }
- while(choice != 4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement