-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBicycle.java
More file actions
154 lines (134 loc) · 4.78 KB
/
Bicycle.java
File metadata and controls
154 lines (134 loc) · 4.78 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package creational.builder;
public class Bicycle {
// Required fields
private final String frameSize;
private final int wheelSize;
private final String color;
// Optional fields
private final String frameMaterial;
private final String brakeType;
private final int gearCount;
private final String tireType;
private final String suspensionType;
private final String handlebarType;
private final boolean hasBell;
private final boolean hasCarrier;
private final String seatType;
private final boolean hasLights;
private final boolean hasKickstand;
private final double weight;
private Bicycle(Builder builder) {
this.frameSize = builder.frameSize;
this.wheelSize = builder.wheelSize;
this.color = builder.color;
this.frameMaterial = builder.frameMaterial;
this.brakeType = builder.brakeType;
this.gearCount = builder.gearCount;
this.tireType = builder.tireType;
this.suspensionType = builder.suspensionType;
this.handlebarType = builder.handlebarType;
this.hasBell = builder.hasBell;
this.hasCarrier = builder.hasCarrier;
this.seatType = builder.seatType;
this.hasLights = builder.hasLights;
this.hasKickstand = builder.hasKickstand;
this.weight = builder.weight;
}
@Override
public String toString() {
return "Bicycle{" +
"frameSize='" + frameSize + '\'' +
", wheelSize=" + wheelSize +
", color='" + color + '\'' +
", frameMaterial='" + frameMaterial + '\'' +
", brakeType='" + brakeType + '\'' +
", gearCount=" + gearCount +
", tireType='" + tireType + '\'' +
", suspensionType='" + suspensionType + '\'' +
", handlebarType='" + handlebarType + '\'' +
", hasBell=" + hasBell +
", hasCarrier=" + hasCarrier +
", seatType='" + seatType + '\'' +
", hasLights=" + hasLights +
", hasKickstand=" + hasKickstand +
", weight=" + weight +
'}';
}
public static class Builder {
// Required
private final String frameSize;
private final int wheelSize;
private final String color;
// Optional - with default values
private String frameMaterial = "Aluminum";
private String brakeType = "Rim";
private int gearCount = 1;
private String tireType = "Road";
private String suspensionType = "None";
private String handlebarType = "Flat";
private boolean hasBell = false;
private boolean hasCarrier = false;
private String seatType = "Comfort";
private boolean hasLights = false;
private boolean hasKickstand = false;
private double weight = 10.0;
// Builder constructor with required fields
public Builder(String frameSize, int wheelSize, String color) {
this.frameSize = frameSize;
this.wheelSize = wheelSize;
this.color = color;
}
// Optional setters
public Builder frameMaterial(String frameMaterial) {
this.frameMaterial = frameMaterial;
return this;
}
public Builder brakeType(String brakeType) {
this.brakeType = brakeType;
return this;
}
public Builder gearCount(int gearCount) {
this.gearCount = gearCount;
return this;
}
public Builder tireType(String tireType) {
this.tireType = tireType;
return this;
}
public Builder suspensionType(String suspensionType) {
this.suspensionType = suspensionType;
return this;
}
public Builder handlebarType(String handlebarType) {
this.handlebarType = handlebarType;
return this;
}
public Builder hasBell(boolean hasBell) {
this.hasBell = hasBell;
return this;
}
public Builder hasCarrier(boolean hasCarrier) {
this.hasCarrier = hasCarrier;
return this;
}
public Builder seatType(String seatType) {
this.seatType = seatType;
return this;
}
public Builder hasLights(boolean hasLights) {
this.hasLights = hasLights;
return this;
}
public Builder hasKickstand(boolean hasKickstand) {
this.hasKickstand = hasKickstand;
return this;
}
public Builder weight(double weight) {
this.weight = weight;
return this;
}
public Bicycle build() {
return new Bicycle(this);
}
}
}