-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParrot.java
More file actions
32 lines (25 loc) · 875 Bytes
/
Copy pathParrot.java
File metadata and controls
32 lines (25 loc) · 875 Bytes
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
package com.example.cleancoder.repeatedswitch;
public abstract class Parrot {
protected final ParrotTypeEnum type;
protected Parrot(ParrotTypeEnum type) {
this.type = type;
}
public static Parrot of(ParrotTypeEnum type, int numberOfCoconuts, double voltage, boolean isNailed) {
return switch (type) {
case EUROPEAN -> new EuropeanParrot();
case AFRICAN -> new AfricanParrot(numberOfCoconuts);
case NORWEGIAN_BLUE -> new NorwegianBlueParrot(voltage, isNailed);
};
}
protected double getBaseSpeed(double voltage) {
return Math.min(24.0, voltage * getBaseSpeed());
}
protected double getLoadFactor() {
return 9.0;
}
protected double getBaseSpeed() {
return 12.0;
}
public abstract double getSpeed();
public abstract String getCry();
}