Commit 3adaf086 authored by Jiri Sebek's avatar Jiri Sebek
Browse files

1.cviceni

parents
# Enterprice architect model
*.EAP
# Exported diagrams
*.png
# Intellij
.idea/
*.iml
*.iws
# Maven
log/
target/
\ No newline at end of file
# B191_B6B36OMO
import java.util.ArrayList;
import java.util.List;
public class Car extends CarPart {
private int makeYear;
private int color;
private List <Wheel> wheels = new ArrayList<>();
public Car(int wheelsCount, int wheelRadius, int makeYear, int color) {
this.makeYear = makeYear;
this.color = color;
for(int i=0; i<wheelsCount; i++){
wheels.add(new Wheel(wheelRadius));
}
}
public int getMakeYear() {
return makeYear;
}
public int getColor() {
return color;
}
}
import java.util.Calendar;
public class CarFactory {
private int carsMade = 0;
public int getCarsMade() {
return carsMade;
}
private void makingCar(String label){
carsMade++;
System.out.println(label);
}
Car vytvorNakladni(int color){
makingCar("Vytvarim nakladni auto");
return new Car(6,50, Calendar.getInstance().get(Calendar.YEAR),color);
}
Car vytvorOsobni(int color){
makingCar("Vytvarim osobni auto");
return new Car(4,17, Calendar.getInstance().get(Calendar.YEAR), color);
}
}
public class CarPart {
}
public class Homework1 {
public static void main(String[] args) {
System.out.println("Vytvarim auta");
CarFactory carFactory = new CarFactory();
carFactory.vytvorNakladni(0);
carFactory.vytvorNakladni(0);
carFactory.vytvorOsobni(0);
carFactory.vytvorOsobni(0);
carFactory.vytvorNakladni(0);
System.out.println("Vytvoreno " + carFactory.getCarsMade() + " aut");
}
}
public class Wheel extends CarPart {
private int radius;
public Wheel(int radius) {
this.radius = radius;
}
public int getRadius() {
return radius;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment