Repository navigation
Expand file tree
/
Copy pathChange.java
More file actions
134 lines (119 loc) · 2.94 KB
/
Copy pathChange.java
File metadata and controls
134 lines (119 loc) · 2.94 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* This is a class representing a pocketful of
*
* My Tu Le
* 19 February, 2026
*/
public class Change
{
//properties
private int quarters;
private int dimes;
private int nickles;
private int pennies;
//constructor
public Change(int q, int d, int n, int p)
{
this.quarters = q;
this.dimes = d;
this.nickles = n;
this.pennies = p;
}
//accessors - get value of coin
// getQuarters() — returns the quarters int
public int getQuarters()
{
return quarters;
}
// getDimes() — returns the dimes int
public int getDimes()
{
return dimes;
}
// getNickles() — returns the nickles int
public int getNickles()
{
return nickles;
}
// getPennies() — returns the pennies int
public int getPennies()
{
return pennies;
}
//mutators
// setQuarters(int quarters) — updates the quarters field
public boolean setQuarters(int quarters)
{
if (quarters >= 0)
{
this.quarters = quarters;
return true;
}
else
return false;
}
// setDimes(int dimes) — updates the dimes field
public boolean setDimes(int dimes)
{
if (dimes >= 0)
{
this.dimes = dimes;
return true;
}
else
return false;
}
// setNickles(int nickles) — updates the nickles field
public boolean setNickles(int nickles)
{
if (nickles >= 0)
{
this.nickles = nickles;
return true;
}
else
return false;
}
// setPennies(int pennies) — updates the pennies field
public boolean setPennies(int pennies)
{
if (pennies >= 0)
{
this.pennies = pennies;
return true;
}
else
return false;
}
//calcTotal() - to calculate the total and change it to how much Dollar
public double calcTotal()
{
double total = ((quarters*0.25)+(dimes*0.10)+(nickles*0.05)+pennies*0.01);
return total;
}
//toString() - change the number total to String
public String toString()
{
return "# of Quarters: " + quarters + "\n"
+ "# of Dimes: " + dimes + "\n"
+ "# of Nickels: " + nickles + "\n"
+ "# of Pennies: " + pennies + "\n"
+ String.format("Total: $%.2f", calcTotal());
}
//equals()
public boolean equals (Change otherChange)
{
return ((this.quarters == otherChange.quarters) &&
(this.dimes == otherChange.dimes) &&
(this.nickles == otherChange.nickles) &&
(this.pennies == otherChange.pennies));
}
}
/**Notes:
* create type - variable
* recall
* get & change
* set the value
* cal
* change type to String -> fit prompt
*/