CECS 277
LAB ASSIGNMENT 4
Assigned date: Wednesday 10/4
Due date: Monday 10/16
30 points


Objectives

Prelab

Problem 1 [5 points] - Checking Monday, October 9.

Implement the Cake problem discussed in the class using the Factory Method pattern.
Cake is the abstract class, all different cake classes inherit from this class. Cake class has three properties; name of the cake, type of the cake
(whether cake contains butter or it is butter less) and the last one is price. The class Cake has two abstract methods:

void recipe()
void comments()

It also has another public method called aboutCake( ). The method provides the name and the price of the cakes and the comments about the cake.

Create three subclasses from the class Cake.

Encapsulating Object Creation

You are going to define a factory interface and a concrete factory class (CakeFactory) that implements factory interface which will encapsulate the object creation code for different types of cakes.

public interface Factory
{ Cake createCake(String cakeName);
}
public class CakeFactory implements Factory
{ public Cake createCake(String cakeName)
{
...........
}

Create a class Test to test the class CakeFactory.

Problem 2 [5 points] - Checking Monday, October 9.

Implement the Computer problem discussed in the class using the Abstract Factory pattern.

public abstract class Computer {

public abstract String getRAM();
public abstract String getCPU();

@Override
public String toString(){
return "RAM= "+this.getRAM()+", CPU="+this.getCPU();
}
}
public class PC extends Computer
{

private String ram;
private String cpu;

public PC(String ram, String cpu)
{

}
//Override
public String getRAM() {

}

//Override
public String getCPU() {

}

}
public class Server extends Computer
{
.........
}

public interface ComputerAbstractFactory {

public Computer createComputer();

}
public class PCFactory implements ComputerAbstractFactory
{
private String ram;
private String cpu;

public PCFactory(String ram, String cpu)
{

}
//Override
public Computer createComputer()
{
...........
}

}
public class ServerFactory implements ComputerAbstractFactory
{
............
}
public class ComputerFactory {

public static Computer getComputer(ComputerAbstractFactory factory)
{
.....................
}
}

Create a class Test to test the class Computer Factory.


Problem 3-[20 points] Rewrite the lab assignment 2 using the Factory Pattern design.