-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeePot.java
More file actions
56 lines (47 loc) · 1.56 KB
/
Copy pathCoffeePot.java
File metadata and controls
56 lines (47 loc) · 1.56 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
public class CoffeePot {
// first thing is fields-- availalbe always (unlike constructors)
private int cups;
private String blend;
//next thing is constructors
public CoffeePot (){ //default constructor has no parameters
cups = 12;
blend = "Dunkin' Donuts Original Blend";
}
//another constructor (only cups)
public CoffeePot (int numCups){
cups = numCups;
blend = "Dunkin' Donuts Original Blend";
}
//another constructor (only blend)
public CoffeePot (String specialBlend){
cups = 12;
blend = specialBlend;
}
//another constructor (cups and blend)
public CoffeePot (int numCups, String specialBlend){
cups = numCups;
blend = specialBlend;
}
//next thing is additional methods:
public void pourCup (){ //pours a single cup of coffee
//void b/c no return type b/c not returning anything
//also no parameters so () are empty
cups--; //also could do 'cups = cups -1;' or 'cups -= 1;'
}
public void fillPot (String specificBlend){
//parameter could have the same name as before 'specialBlend'
cups = 12;
blend = specificBlend; //ask about THIS LINE
}
public void fillPot (){
cups = 12;
}
//getter methods, accessor methods
public int getCups (){ //returns # of cups
//usually getter methods have something like 'get' in name
return cups;
}
public String getBlend (){ //returns current blend name
return blend;
}
}