Car.java
public class Car
{
public CarParts[] parts=new CarParts[10];
int c=0;
/**
@roseuid 56553BC001D7
*/
public Car()
{
System.out.println("Car is initialised and will get assembled now...\n");
}
/**
@roseuid 56553AFA020A
*/
public void add(CarParts cp)
{
parts[c++]=cp;
}
/**
@roseuid 56553B060252
*/
public void assemble()
{
for(int i=0;i<c;i++)
parts[i].display();
System.out.println("\nCar has been prepared...");
}
}
CarParts.java
public interface CarParts
{
/**
@roseuid 56553B6E02AD
*/
public void display();
}
//Source file: C:\\Program Files\\Java\\jdk1.7.0_80\\bin\\Engine.java
public class Engine implements CarParts
{
/**
@roseuid 56553BC002A4
*/
public Engine()
{
System.out.println("Engine created");
}
/**
@roseuid 56553B980173
*/
public void display()
{
System.out.println("Engine added");
}
}
Wheels.java
public class Wheels implements CarParts
{
/**
@roseuid 56553BC003C9
*/
public Wheels()
{
System.out.println("Wheels created");
}
/**
@roseuid 56553B9D017F
*/
public void display()
{
System.out.println("Wheels added");
}
}
WindShield.java
public class WindShield implements CarParts
{
/**
@roseuid 56553BC0032F
*/
public WindShield()
{
System.out.println("Wind-shield created");
}
/**
@roseuid 56553B910256
*/
public void display()
{
System.out.println("Wind-shield added");
}
}
Factory.java
public class Factory
{
/**
@roseuid 56553BC00113
*/
public Factory()
{
}
/**
@roseuid 56553AD60084
*/
public static void main(String[] args)
{
Car car=new Car();
Engine e=new Engine();
WindShield ws=new WindShield();
Wheels w=new Wheels();
car.add(e);
car.add(ws);
car.add(w);
car.assemble();
}
}