Answer to Question #275426 in Java | JSP | JSF for hatipo

Question #275426

2 Problem description In this labwork you are expected to implement a program that builds a computer for different purposes using Template Method pattern. Your program needs to able to build two types of computers which is Gaming and Office. CPU, Memory and type of storage depends on the computer type. For a gaming computer you need to put: ∗ High-end multi-core cpu ∗ High-clock speed memory ∗ SSD storage For an office computer you need to put: ∗ Low-end dual-core cpu ∗ Energy-efficient memory ∗ Energy-efficient HDD However, way you build a computer is a set of pre-determined steps: ∗ Plug CPU ∗ Plug Memory ∗ Plug Storage ∗ Plug peripherals (which are common for both type of computer)

3 Measure of success You are expected to implement necessary classes for this example using Template Method Pattern.


1
Expert's answer
2021-12-04T12:13:06-0500
abstract class Computer {
  abstract void plugCPU();
  abstract void plugMemory();
  abstract void plugStorage(); 
}

class GamingComputer extends Computer {
  @Override
  void plugCPU() {
    System.out.println(" * High-end multi-core cpu");
  }
  @Override
  void plugMemory() {
    System.out.println(" * High-clock speed memory");
  }
  @Override
  void plugStorage() {
    System.out.println(" ∗ SSD storage");
  }
}

class OfficeComputer extends Computer {
  @Override
  void plugCPU() {
    System.out.println("∗ Low-end dual-core cpu");
  }
  @Override
  void plugMemory() {
    System.out.println("∗ Energy-efficient memory");
  }
  @Override
  void plugStorage() {
    System.out.println("∗ Energy-efficient HDD");
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS