-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBicycle.java
More file actions
93 lines (74 loc) · 2.26 KB
/
Copy pathBicycle.java
File metadata and controls
93 lines (74 loc) · 2.26 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
package com.three19;
public class Bicycle extends TwoWheeled {
// instance variable declarations
private int gears = 0;
private double cost = 0.0;
private double weight = 0.0;
private String color = "";
// constructor - default
Bicycle() {
}
// constructor - String parameter
Bicycle(String aColor) {
this.color = aColor;
}
// constructor - int parameter
Bicycle(int nbrOfGears) {
this.gears = nbrOfGears;
}
// constructor - int, double, double, String parameters
Bicycle(int nbrOfGears, double theCost, double theWeight, String aColor) {
this.gears = nbrOfGears;
this.cost = theCost;
this.weight = theWeight;
this.color = aColor;
}
// method to output Bicycle's information
public void outputData() {
System.out.println("\nBicycle Details:");
System.out.println("Gears : " + this.gears);
System.out.println("Cost : " + this.cost);
System.out.println("Weight : " + this.weight + " lbs");
System.out.println("Color : " + this.color);
}
// method to output Bicycle's information - overloaded
// - method call chaining enabled
public Bicycle outputData(String bikeText) {
System.out.println("\nBicycle " + bikeText + " Details:");
System.out.println("Gears : " + this.gears);
System.out.println("Cost : " + this.cost);
System.out.println("Weight : " + this.weight + " lbs");
System.out.println("Color : " + this.color);
return this;
}
// Accessors (Getters)
public int getGears() {
return this.gears;
}
public double getCost() {
return this.cost;
}
public double getWeight() {
return this.weight;
}
public String getColor() {
return this.color;
}
// Mutators (Setters) - method call chaining enabled
public Bicycle setGears(int nbr) {
this.gears = nbr;
return this;
}
public Bicycle setCost(double amt) {
this.cost = amt;
return this;
}
public Bicycle setWeight(double lbs) {
this.weight = lbs;
return this;
}
public Bicycle setColor(String theColor) {
this.color = theColor;
return this;
}
}