-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoal.java
More file actions
52 lines (45 loc) · 1.2 KB
/
Copy pathGoal.java
File metadata and controls
52 lines (45 loc) · 1.2 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
public class Goal{
//instance variables
double reach;
boolean given;
double value;
//constructor assigns reach and value
public Goal(double v,double r){
value = v ;
given = false;
reach =r;
}
//new toString based on its deliverance
public String toString()
{
if (given == false){
return "$" + reach + " has not been activated :(";
}
else{
return "$" + reach + " has been acheived!";
}
}
//give player the money
public void reward(Player p){
//if player reached goal and it hasnt been given
if (p.getDol() > reach && given == false){
//give new worth to player
p.newWorth(p.getDol() + value);
given = true;
System.out.println("You have just won $" + value + "for reaching $" + reach +".");
}
else{
if (given == true){
System.out.println("Cheater, you already achieved this goal");
}else{
System.out.println("You have not reached $" + reach + ".");}
}
}
//test
// public static void main(String[] args){
// Player me = new Player("me","hello",23.3);
// Goal test = new Goal(10.2,5);
// System.out.println(me);
// test.reward(me);
// System.out.println(me);}
}