-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDie.java
More file actions
85 lines (62 loc) · 1.9 KB
/
Die.java
File metadata and controls
85 lines (62 loc) · 1.9 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
/*
* Name : Harpreet Kaur
* Student number: A00245132
* Description: Getter Setter class that replicates dice class
*/
public class Die {
// declares variables which defines dice
// describe dice type or name
String die_name;
// describe no of slides
int no_of_sides;
// describe current upward side or random number
int curr_side_up;;
//default constructor(without arguments)
Die(){
this.die_name="d6";
this.no_of_sides=6;
this.curr_side_up=(int)(Math.random()*no_of_sides) + 1;
}
//single parameter constructor(no_of_sides is argument)
Die(int no_of_sides){
this.no_of_sides=no_of_sides;
this.curr_side_up=(int)(Math.random()*no_of_sides) + 1;
this.die_name="d"+no_of_sides;
}
//2-parameterized constructor(no_of_sides and die_name are arguments )
Die(int no_of_sides,String die_name){
this.no_of_sides=no_of_sides;
this.die_name=die_name;
this.curr_side_up=(int)(Math.random()*no_of_sides) + 1;
}
// accessors and mutators
// a getter method to fetch the dice_name
public String getDie_name() {
return die_name;
}
// a setter method that assign a value to the die_name variable
public void setDie_name(String die_name) {
this.die_name = die_name;
}
//a getter method to fetch the no_of_sides
public int getNo_of_sides() {
return no_of_sides;
}
//a setter method that assign a value to the no_of_sides variable
public void setNo_of_sides(int no_of_sides) {
this.no_of_sides = no_of_sides;
}
//a getter method to fetch the curr_side_up
public int getCurr_side_up() {
return curr_side_up;
}
//a setter method that assign a value to the curr_side_up variable
public void setCurr_side_up(int curr_side_up) {
this.curr_side_up = curr_side_up;
}
//roll method generating random value
void roll() {
curr_side_up = (int)(Math.random()*no_of_sides) + 1;
System.out.println("The new value is "+curr_side_up);
}
}