package abstractFactory;
public class FleetRun {
protected String planFile =
"abstractFactory/fleet.properties";
protected Fleet myFleet;
public static void main
(String[] args
) { FleetRun program = new FleetRun();
// get the fleet plan
try {
program.ReadPlan();
System.
out.
println("Problems with config file: " + program.
getPlanFile());
}
// create definite factory
FleetFactory factory = program.GetFactory(program.getPlan().getProperty("factory"));
// create fleet using created factory
program.CreateFleet(factory);
System.
out.
println(program.
getMyFleet());
}
public void CreateFleet(FleetFactory factory) {
byte carNum =
Byte.
parseByte(plan.
getProperty("carNum"));
byte truckNum =
Byte.
parseByte(plan.
getProperty("truckNum"));
byte busNum =
Byte.
parseByte(plan.
getProperty("busNum"));
myFleet = new Fleet("WWW CarFleet");
// cars >>
for (int i = 1; i <= carNum; i++) {
number = "w00" + i + "ww77rus";
myFleet.AddCar(factory.MakeCar(number));
}
// trucks >>
for (int i = 1; i <= truckNum; i++) {
number = "w0" + i + "0ww77rus";
myFleet.AddTruck(factory.MakeTruck(number));
}
// buses
for (int i = 1; i <= busNum; i++) {
number = "w00" + i + "ww77rus";
myFleet.AddBus(factory.MakeBus(number));
}
}
plan.load(fin);
fin.close();
return plan;
}
public FleetFactory GetFactory
(String id
) { if ("ru".equals(id)) {
return new RusFleetFactory();
} else {
return new AmericanFleetFactory();
}
}
public Fleet getMyFleet() {
return myFleet;
}
return plan;
}
return planFile;
}
}