Laptop store

Report a typo

Imagine you are the owner of a LaptopStore. Your engineer must be able to create 17'', 15'' or 13'' laptops without any concrete details. Write the code to make that happen.

Sample Input 1:

Sample Output 1:

Making a 13 inch Laptop
Attaching keyboard
Attaching trackpad
Attaching display
Ready 13 inch Laptop

Making a 15 inch Laptop
Attaching keyboard
Attaching trackpad
Attaching display
Ready 15 inch Laptop

Making a 17 inch Laptop
Attaching keyboard
Attaching trackpad
Attaching display
Ready 17 inch Laptop

Available laptops in the store:
13 inch Laptop
15 inch Laptop
17 inch Laptop
Write a program in Java 17
class TestDrive {
public static void main(String[] args) throws InterruptedException {
LaptopStore laptopStore = /* write your code here */

Laptop laptop13 = laptopStore.orderLaptop("13 inch");
Laptop laptop15 = laptopStore.orderLaptop("15 inch");
Laptop laptop17 = laptopStore.orderLaptop("17 inch");

System.out.println("Available laptops in the store:");
System.out.println(laptop13);
System.out.println(laptop15);
System.out.println(laptop17);
}
}

abstract class LaptopFactory {

abstract Laptop createLaptop(String type);

Laptop orderLaptop(String type) throws InterruptedException {
Laptop laptop = createLaptop(type);
if (laptop == null) {
System.out.println("Sorry, we are unable to create this kind of laptop\n");
return null;
}
System.out.println("Making a " + laptop.getName());
laptop.attachKeyboard();
laptop.attachTrackpad();
laptop.attachDisplay();
Thread.sleep(1500L);
System.out.println("Ready " + laptop.getName() + "\n");
return laptop;
}
}

class LaptopStore extends LaptopFactory {
___

Create a free account to access the full topic