-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBusiness.java
More file actions
122 lines (107 loc) · 4.61 KB
/
Business.java
File metadata and controls
122 lines (107 loc) · 4.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**************************************************************************************************
* Program Name : Final Project Option #2 - Lemonade Stand
* Author : Terry Weiss
* Date : May 5, 2016
* Course/Section : CSC 112-801 Fundamentals of Computing II
* Program Description: The Lemonade Stand program runs a simulation for 30 days to make as much
* money as possible. The player starts with one stand and $100, and can buy as many stands as
* they'd like. Each day starts with weather reports where it can be rainy, cloudy, or sunny.
* The weather can be different for each stand. Each stand also generates the price per cup of
* lemonade based on the random daily price of each ingredient. The player may also make signs
* that add 1% of the customers per sign made. Each stand has its own pool of signs, since they
* are in different locations. The player is given the weather report and cost per cup, and is
* then prompted for how many cups and signs they'd like to make.
*
* The stands then generate how many customers per hour visit based on the weather, and whether each
* customer wants to buy the lemonade based on the price, the weather, and their generosity or
* stinginess. As each stand is simulated, its profits and expenses are added to the daily
* total. Once the day is over, a report will be displayed for each stand's results, and the
* daily profits will be added to the business's money pool.
*
* The game also records the player's final amount of money as a score, and a high score is
* maintained holding the top 5 scores. If the player's score qualifies, they will be prompted
* for their name, and the score will be inserted into the high scores list. The high scores
* list is saved to a file in serialized state and persists between games.
**************************************************************************************************/
package lemonadestand;
import java.util.LinkedList;
/**
* The business class holds the locations of all the Stands in the current game and also keeps
* track of how much money is held between all of them.
*
* @author Terry Weiss
*/
public class Business {
public static final double STAND_PRICE = 150.00; //Cost of a new stand
public static final double STARTING_MONEY = 100.00; //Money you start with in each stand
private final LinkedList<Stand> locations; //Linked list of the Stands/business locations
private double money; //How much money the business since last close of business day
/**
* Constructs a new Business. This creates and adds your first stand to the list of locations
* for free, and also sets up your initial money.
*
* @param initialStand The first stand to be added (given for free)
*/
public Business(Stand initialStand) {
money = STARTING_MONEY;
locations = new LinkedList<>();
locations.add(initialStand);
}
/**
* Gets how much money the business has.
*
* @return Business's money
*/
public double getMoney() {
return money;
}
/**
* The spend method takes the given expense away from the business's money if it has enough
* money. If the expense is negative, an IllegalArgumentException will be thrown.
*
* @param expense Amount of the expense
* @throws IllegalArgumentException If expense is negative
* @return Whether the expense was spent
*/
public boolean spend(double expense) {
boolean spent = false;
if (expense < 0) {
throw new IllegalArgumentException("Negative expenses aren't allowed:" + expense);
} else if (money >= expense) {
money -= expense;
spent = true;
}
return spent;
}
/**
* Adds the specified profit to the business's money pool.
*
* @param profit Amount of profit
*/
public void addProfit(double profit) {
money += profit;
}
/**
* Buys a new stand if there's enough money, and adds the stand to the list of locations.
*
* @param newStand New Stand to be added
* @return Whether stand was able to be added
*/
public boolean buyStand(Stand newStand) {
boolean added = false;
if (money >= STAND_PRICE) {
money -= STAND_PRICE;
locations.add(newStand);
added = true;
}
return added;
}
/**
* Gets the list of locations as a linked list.
*
* @return Linked List of locations
*/
protected LinkedList<Stand> locations() {
return locations;
}
}