-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopper_IM.java
More file actions
61 lines (55 loc) · 1.18 KB
/
Shopper_IM.java
File metadata and controls
61 lines (55 loc) · 1.18 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
/**
* This class is an abstraction for the shopper.
* The shopper has their balance as an instance.
*
* @IMukhametzhanova
* @1.8
* 11/8/18
*/
public class Shopper_IM
{
private double money;
/**
* Constructor with zero balance
*/
public Shopper_IM ()
{
money = 0;
}
/**
* Constructor with entered balance
*/
public Shopper_IM (double money)
{
this.money = money;
}
/**
* Method to access the shopper's current balance
*/
public double getMoney()
{
return money;
}
/**
* When the shopper buys something.
* Subtracts the cost from their current balance.
*/
public boolean boughtOne(double cost)
{
boolean canBuy = false;
if (cost > money) System.out.println("You don't have enough money to buy this");
else {
money -= cost;
canBuy = true;
}
return canBuy;
}
/**
* Converts the shopper's info to string
*/
public String toString()
{
String output = "Current balance: $" + money;
return output;
}
}