-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sundae.java
114 lines (102 loc) · 2.41 KB
/
Sundae.java
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
public class Sundae {
//Private variables that can only be accessed with accesors and mutators, for privacy purposes.
private String Flavor;
private int Scoops;
private boolean Nuts;
private double Cost;
private static int Tracker;
// Default constructor: 1)same name, 2)no return at all, 3) public 4) No paramaterizations
public Sundae()
{
Flavor="";
Scoops=0;
Nuts=false;
Cost=0;
Tracker++;
}
//constructor: 1)same name, 2)no return at all, 3) public 4) paramaterizations
public Sundae(int Scoops, String Flavor, boolean Nuts)
{
setScoops(Scoops);
setFlavor(Flavor);
setNuts(Nuts);
Tracker++;
this.calcCost();
}
//Copy constructor
public Sundae(Sundae sundae) {
this.Flavor = sundae.Flavor;
this.Scoops = sundae.Scoops;
this.Nuts = sundae.Nuts;
this.Cost = sundae.Cost;
Tracker++;
}
//Accesors allow the program to get the values, meanwhile Mutators are to change and set values.
//Accessors (usually only return type)
public String getFlavor()
{
return Flavor;
}
// Accessors (usually only return type)
public int getScoops()
{
return Scoops;
}
// Accessors (usually only return type)
public boolean getNuts()
{
return Nuts;
}
//Accessors (usually only return type)
public double getCost()
{
return Cost;
}
//Accessors (usually only return type)
public static int getTracker()
{
return Tracker;
}
// Mutators (usually no return type)
public void setFlavor(String Flavor)
{
this.Flavor=Flavor;
}
//Mutators (usually no return type)
public void setScoops(int Scoops)
{
this.Scoops=Scoops;
}
//Mutators (usually no return type)
public void setNuts(boolean Nuts)
{
this.Nuts=Nuts;
}
//This method helps update the cost
public void updateCost()
{
this.calcCost();
}
//This method calculates the cost of the ice cream
private void calcCost()
{
if(Nuts)
Cost= (1.5*Scoops) + 1.25;
else
Cost=1.5*Scoops;
}
//This method checks if the content of two objects are equal
public boolean isEquals(Sundae anotherSundae)
{
return anotherSundae.getFlavor().equals(this.Flavor) && this.Scoops == anotherSundae.getScoops() && this.Nuts == anotherSundae.getNuts();
}
//This method prints out a string
public String toString() {
if (Nuts)
return ("Sundae with " + getScoops() + " scoops" +
" of " + getFlavor() + " with nuts for a cost of: " + this.getCost());
else
return ("Sundae with " + getScoops() + " scoops" +
" of " + getFlavor() + " without nuts for a cost of: " + this.getCost());
}
}