-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubCoin.java
More file actions
72 lines (66 loc) · 1.88 KB
/
subCoin.java
File metadata and controls
72 lines (66 loc) · 1.88 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
/**
* This class extends the Coin class by adding it's denomination. It determines this by checking the monetary value passed to it
* from main against a switch statement.
* @author Michael Chadwick
* @version 2/20/20
*/
public class subCoin extends Coin
{
int coinValue; //The coin's monetary value.
String coinType; //The coin's denomination(ie PENNY, NIKEL, etc).
/**
* Constructs a nec coin object from the Coin superclass and the value passed to it.
* It then calls the getType method to determine it's type by passing it the coin's value.
* @param coinValue - the coin's monetary value.
*/
public subCoin(int coinValue)
{
super();
this.coinValue = getValue();
this.coinType = getType(coinValue);
}
/**
* This method uses a switch statement to determine the coin's denomination by comparing it's value vs the cases.
* @param coinValue - the coin's monetary value.
* @return coinType - the coin's denomination.
*/
public String getType(int coinValue)
{
switch(coinValue)
{
case 1:
coinType = "PENNY";
break;
case 5:
coinType = "NIKEL";
break;
case 10:
coinType = "DIME";
break;
case 25:
coinType = "QUARTER";
break;
case 50:
coinType = "HALF-DOLLAR";
break;
}
return coinType;
}
/**
* This method returns the coin's value.
* @return coinValue - returns the coin's value.
*/
public int getValue()
{
return coinValue;
}
/**
* This method returns the coins type as a string.
* @return coinType - returns the coin's denomination as a string.
*/
@Override
public String toString()
{
return (coinType);
}
}