Repository navigation
Expand file tree
/
Copy pathCup.java
More file actions
91 lines (73 loc) · 1.98 KB
/
Copy pathCup.java
File metadata and controls
91 lines (73 loc) · 1.98 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
/**
@author John Nguyen
Date: 08/30/2022
Class CSCI
Instructor
Illustration of classes and methods
//============================ To Do: ==================
//1. default constructor
//2. override the toString method
//3. come up with your own application for these classes
//======================================================
*/
import java.util.*;
interface Spillable{
}
public class Cup{
//attributes
private double maxVol; //maximum volume
private double actVol; //current volume
//functionalities
/** default constructor */
public Cup(){
this.maxVol = 32.0;
this.actVol = 0.0;
}
/** .. */
public Cup(double maxVol, double curVol){
this.maxVol = maxVol;
this.actVol = curVol;
}
// GETTER, allows the extended class to get maxVol
public double getMaxVol() {
return this.maxVol;
}
// GETTER, allows the extended class to get actVol
public double getActVol() {
return this.actVol;
}
/** Allows to display method as String*/
public String toString(){
return "Max volume: " + this.maxVol +
"\nActual Volume: " + this.actVol;
}
/**driver*/
public static void main(String[] args){
Mug y = new Mug(5.0,6.5,3.5);
System.out.println(y);
System.out.println();
Cup x = new Cup(6.5,3.5);
System.out.println(x);
}
}
//extending the class
/** .. */
class Mug extends Cup{
//attribute
private double dryWeight; //Weight of Mug
//deafult constructor
public Mug(){
this.dryWeight = 10.0;
}
//
public Mug(double weight, double maxVol, double actVol){
super(maxVol, actVol);
this.dryWeight = weight;
}
//Allows to display method as string
public String toString(){
return "Weight: " + this.dryWeight +
"\nMax Volume: " + getMaxVol() +
"\nActual Volume: " + getActVol();
}
}