-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFactory
More file actions
60 lines (43 loc) · 1.03 KB
/
Factory
File metadata and controls
60 lines (43 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
public class Demo {
public static void main(String[] args) {
MilkFactory factory = new MilkFactory();
Milkable glass = factory.getMilk(10);
glass.makeMilk();
Milkable bottle = factory.getMilk(5);
bottle.makeMilk();
}
}
class MilkFactory {
public Milkable getMilk(int vetpercentage){
if (vetpercentage==5){
return new Donkey();
}else if (vetpercentage==10){
return new Goat();
}else if (vetpercentage==15){
return new Cow();
}
return null;
}
}
class Cow implements Milkable{
@Override
public void makeMilk() {
System.out.println("15% koemelk");
}
}
class Goat implements Milkable{
@Override
public void makeMilk() {
System.out.println("10% geitenmelk");
}
}
class Donkey implements Milkable{
@Override
public void makeMilk() {
System.out.println("5% ezelmelk");
}
}
//////////////////////////////
public interface Milkable {
void makeMilk();
}