04 Laboratory Exercise 1
04 Laboratory Exercise 1
@Override
public String toString()
{
return "RAM=" + this.getRAM() + "GB, SSD=" + this.getSSD() + "CPU=" +
this.getCPU();
}
}
Sub Class:
public class Minimum extends Laptop
{
private final int ram;
private final int ssd;
private final String cpu;
Sub Class:
public class Recommended extends Laptop
{
private final int ram;
private final int ssd;
private final String cpu;
Class:
public class LaptopFactory
{
public static Laptop getSpecs(String type, int ram, int ssd, String cpu)
{
if("min".equalsIgnoreCase(type))
{
return new Minimum(ram, ssd, cpu);
}
else if("reco".equalsIgnoreCase(type))
{
return new Recommended(ram, ssd, cpu);
}
return null;
}
}
Main Method:
public class TestFactory
{
public static void main(String[] args)
{
Laptop min = LaptopFactory.getSpecs("min", 8, 256, "i5-12450Hz");
Laptop reco = LaptopFactory.getSpecs("reco", 8, 512, "i7-12700Hz");
Output: