Professional Documents
Culture Documents
04 Lab Exer 1
04 Lab Exer 1
Create an abstract superclass named Laptop. Any subclass of an abstract class must
either implement all of the abstract methods in the superclass or be declared
abstract itself. Copy the code below.
abstract class Laptop {
Create three (3) public getter methods named after the abstract methods in your
superclass. These methods should return the value of the instance variables. Ex.
return this.ram;
Add another subclass named Recommended that also extends the same superclass. This
class shall have the same content with your Minimum class.
Add a class named LaptopFactory. Copy the code below for its method.
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;
}
Use the public class named TestFactory to execute your Factory Method pattern
implementation. In its main method, instantiate a Laptop object named min. Copy the
code below.
Laptop min = LaptopFactory.getSpecs("min", 8, 256, "i5-12450Hz");
Instantiate another Laptop object named reco. Follow the syntax above but use the
following values for the 2nd to 4th parameter: 16, 512, i7-12700Hz
Display the content of the two (2) objects in separate lines.
Sample Output:
Minimum Specs:
RAM=8GB, SSD=256, CPU=i5-12450Hz
Recommended Specs:
RAM=16GB, SSD=512, CPU=i7-12700Hz