forked from jcrouser/CSC120-A8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCafe.java
More file actions
144 lines (134 loc) · 4.77 KB
/
Copy pathCafe.java
File metadata and controls
144 lines (134 loc) · 4.77 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* This is a stub for the Cafe class */
/**
* The Cafe class which extends the building class and adds the attributes nCoffeeOunces, nSugarPackets, nCreams, and nCups.
*/
public class Cafe extends Building {
private int nCoffeeOunces;
private int nSugarPackets;
private int nCreams;
private int nCups;
/**
* Constructor for the Cafe class
* @param name
* @param address
* @param nFloors
* @param nCoffeeOunces
* @param nSugarPackets
* @param nCreams
* @param nCups
*/
public Cafe(String name, String address, int nFloors, int nCoffeeOunces, int nSugarPackets, int nCreams, int nCups) {
super(name, address, nFloors);
this.nCoffeeOunces = nCoffeeOunces;
this.nSugarPackets = nSugarPackets;
this.nCreams = nCreams;
this.nCups = nCups;
}
/**
* Constructor for the Cafe class with preset params for cafe contents
* @param name
* @param address
* @param nFloors
*/
public Cafe(String name, String address, int nFloors) {
super(name, address, nFloors);
this.nCoffeeOunces = 100;
this.nSugarPackets = 100;
this.nCreams = 100;
this.nCups = 100;
}
/**
* Reduces the number of supplies in the cafe when coffee is sold. If no supplies are left, it calls the restock method.
* @param size ounces of coffee
* @param nSugarPackets number of sugar packets in coffee
* @param nCreams number of creams in coffee
*/
private void sellCoffee(int size, int nSugarPackets, int nCreams) {
if (this.nCoffeeOunces > 0 && this.nSugarPackets > 0 && this.nCreams > 0 && this.nCups > 0) {
this.nCoffeeOunces -= size;
this.nSugarPackets -= nSugarPackets;
this.nCreams -= nCreams;
this.nCups -= 1;
}
else {
restock(size, nSugarPackets, nCreams, 1);
this.nCoffeeOunces -= size;
this.nSugarPackets -= nSugarPackets;
this.nCreams -= nCreams;
this.nCups -= 1;
}
}
/**
* sells coffee with preset size, sugar packets, and creams.
*/
private void sellCoffee() {
int size = 10;
int nSugarPackets = 1;
int nCreams = 1;
if (this.nCoffeeOunces > 0 && this.nSugarPackets > 0 && this.nCreams > 0 && this.nCups > 0) {
this.nCoffeeOunces -= size;
this.nSugarPackets -= nSugarPackets;
this.nCreams -= nCreams;
this.nCups -= 1;
}
else {
restock(size, nSugarPackets, nCreams, 1);
this.nCoffeeOunces -= size;
this.nSugarPackets -= nSugarPackets;
this.nCreams -= nCreams;
this.nCups -= 1;
}
}
/**
* Restocks the supplies in the cafe when supplies hit 0.
* @param nCoffeeOunces number of coffee ounces to restock
* @param nSugarPackets number of sugar packets to restock
* @param nCreams number of creams to restock
* @param nCups number of cups to restock
*/
private void restock(int nCoffeeOunces, int nSugarPackets, int nCreams, int nCups) {
if (this.nCoffeeOunces == 0) {
this.nCoffeeOunces += nCoffeeOunces + 100-nCoffeeOunces;
}
if (this.nSugarPackets == 0) {
this.nSugarPackets += nSugarPackets + 100-nSugarPackets;
}
if (this.nCreams == 0) {
this.nCreams += nCreams + 100-nCreams;
}
if (this.nCups == 0) {
this.nCups += nCups + 100-nCups;
}
}
/**
* Prints available methods for the cafe class
*/
public void showOptions() {
System.out.println("Available options at " + this.name + ":\n + enter() \n + exit()");
}
/**
* Keeps user from changing floors in the cafe
* @param floorNum floor number to move to
*/
public void goToFloor(int floorNum) {
throw new RuntimeException("This cafe only has one accessible floor!");
}
/**
* Tester for the cafe class methods
* @param args
*/
public static void main(String[] args) {
Cafe Woodstar = new Cafe("Woodstar", "Noho", 5, 100, 100, 100, 100);
Woodstar.sellCoffee(20,12, 2);
System.out.println("Ounces of coffee left:" + Woodstar.nCoffeeOunces);
Woodstar.sellCoffee(80,12, 2);
System.out.println("Ounces of coffee left:" + Woodstar.nCoffeeOunces);
Woodstar.sellCoffee(10,12, 2);
System.out.println("Ounces of coffee left:" + Woodstar.nCoffeeOunces);
System.out.println("Sugar remaining:" + Woodstar.nSugarPackets);
//Woodstar.goToFloor(6);
Woodstar.showOptions();
Woodstar.sellCoffee();
System.out.println("Ounces of coffee left:" + Woodstar.nCoffeeOunces);
}
}