summaryrefslogtreecommitdiffstats
path: root/Java/Cup/Cup.java
blob: c313c07fff6bcafcc322fd525cf7569b4d56db05 (plain) (blame)
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
public class Cup {

  // data member
  private double capacity;
  private double holding;
  private String color;


  
  // Constructors
  public Cup(double c, String co, double h) {
    capacity = c;
    color = co;
    holding = h;
  }
  public Cup() {
    color = "red";
    capacity = 16;
    holding = 0;
  }
  // set
  public void fillCup(double h) {
    if (h > capacity){
    capacity = holding;	    
    } else {
    holding = holding + h;
    }
  }
  public void sip() {
    if(holding - 1 < 1){
    holding = holding-1;
    } else {
            //System.out.println("CUPPER UNDERFLOW DETECTED");
    }
  }

  public void gulp() {
    if(holding-3 > 1){
    holding = holding-3;
    } else {
	    //System.out.println("CUPPER UNDERFLOW DETECTED");
    }
  }
  public void emptyCup() {
    holding = 0;
  }

  // modify and return
  public String status() {
    return capacity + " ounce " + color + " cup that contains " + holding + " ounce[s].";
  }

}