-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoin.java
More file actions
90 lines (81 loc) · 1.61 KB
/
Coin.java
File metadata and controls
90 lines (81 loc) · 1.61 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
import java.util.Random;
/**
* Flippable Coin super class.
* @author Lisa Miller
* @since 9/9/2017
*/
public class Coin implements Flippable {
//instance variables
private double value;
private String name;
private String color;
//added for flippable
private int upSide;
private int downSide;
/**
* Two parameter constructor
* @param value the coin value
* @param name the coin type name
*/
public Coin (double value, String name) {
this.value = value;
this.name = name;
this.toss(); //randomly set upside/downSide
}
//get methods
public double getValue() {
return this.value;
}
public String getName() {
return this.name;
}
//getColor method returns "Silver"
//by default
public String getColor() {
return "Silver";
}
/**
* Switches value of upSide and downSide.
*/
@Override
public void flip() {
if (upSide == 0) {
upSide = 1;
downSide = 0;
}
else {
upSide = 0;
downSide = 1;
}
}
/**
* Randomly sets upSide and corresponding downSide
*/
@Override
public void toss() {
Random r = new Random();
upSide = r.nextInt(2);
if (upSide == 0){
downSide = 1;
}
else {
downSide = 0;
}
}
/**
* Returns the upSide
* @return the up facing side
*/
@Override
public int getUpSide () {
return upSide;
}
/**
* Sets the upSide
* @param i the new up facing side
*/
@Override
public void setUpSide (int i) {
upSide = i;
}
}