Instructions JAVA LANGUAGE The Factory Method pattern provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects to be created. Use NetBeans to create a Java program that implements this design pattern. Name your project TestFactory. 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 { public abstract int getRAM(); public abstract int getSSD(); public abstract String getCPU(); public String toString() { return "RAM="+this.getRAM()+"GB, SSD="+this.getSSD()+", CPU="+this.getCPU(); } } Create a subclass named Minimum that extends your superclass. In this class, declare three (3) private variables with the following names and data types: ram (int) ssd (int) cpu (String) Copy the code below for the constructor of your Minimum class. This constructor has three (3) parameters: ram, ssd, and cpu. Parameters are separated by commas as seen below. public Minimum(int ram, int ssd, String cpu){ this.ram=ram; this.ssd=ssd; this.cpu=cpu; } 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
Instructions JAVA LANGUAGE The Factory Method pattern provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects to be created. Use NetBeans to create a Java program that implements this design pattern. Name your project TestFactory. 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 { public abstract int getRAM(); public abstract int getSSD(); public abstract String getCPU(); public String toString() { return "RAM="+this.getRAM()+"GB, SSD="+this.getSSD()+", CPU="+this.getCPU(); } } Create a subclass named Minimum that extends your superclass. In this class, declare three (3) private variables with the following names and data types: ram (int) ssd (int) cpu (String) Copy the code below for the constructor of your Minimum class. This constructor has three (3) parameters: ram, ssd, and cpu. Parameters are separated by commas as seen below. public Minimum(int ram, int ssd, String cpu){ this.ram=ram; this.ssd=ssd; this.cpu=cpu; } 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
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2GZ
Related questions
Concept explainers
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Question
Instructions
JAVA LANGUAGE
The Factory Method pattern provides an interface for creating objects in a superclass but allows subclasses to alter the type of objects to be created. Use NetBeans to create a Java program that implements this design pattern. Name your project TestFactory.
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 {
public abstract int getRAM();
public abstract int getSSD();
public abstract String getCPU();
public String toString() {
return "RAM="+this.getRAM()+"GB, SSD="+this.getSSD()+", CPU="+this.getCPU();
}
}
Create a subclass named Minimum that extends your superclass. In this class, declare three (3) private variables with the following names and data types:
ram (int)
ssd (int)
cpu (String)
Copy the code below for the constructor of your Minimum class. This constructor has three (3) parameters: ram, ssd, and cpu. Parameters are separated by commas as seen below.
public Minimum(int ram, int ssd, String cpu){
this.ram=ram;
this.ssd=ssd;
this.cpu=cpu;
}
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
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT