-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHello.java
More file actions
141 lines (133 loc) · 5.85 KB
/
Copy pathHello.java
File metadata and controls
141 lines (133 loc) · 5.85 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
import java.util.Arrays;
import java.util.ArrayList;
class Store {
// instance fields
String productType;
String Streetaddress;
double inventoryPrice;
double customerPayment;
double tax;
double TotalBalance;
ArrayList<String> Ingredients = new ArrayList<String>();
ArrayList<Integer> IngredientCount = new ArrayList<Integer>();
int[] TotalCookies = {0, 0, 0};
String[] CookieTypes = {"chocolate chip", "peanut butter", "peanut butter chocolate"};
boolean Open;
public void BuyIngredients(int newIngredients, double Cost){
double Balance = TotalBalance - Cost;
TotalBalance = Balance;
if(Ingredients.size() == 0){
Ingredients.add(0, "flour");
IngredientCount.add(0, newIngredients);
Ingredients.add(1, "sugar");
IngredientCount.add(1, newIngredients);
Ingredients.add(2, "butter");
IngredientCount.add(2, newIngredients);
Ingredients.add(3, "chocolate chip");
IngredientCount.add(3, newIngredients);
Ingredients.add(4, "peanut butter");
IngredientCount.add(4, newIngredients);
}
else{
IngredientCount.set(0, IngredientCount.get(0) + newIngredients);
IngredientCount.set(1, IngredientCount.get(1) + newIngredients);
IngredientCount.set(2, IngredientCount.get(2) + newIngredients);
IngredientCount.set(3, IngredientCount.get(3) + newIngredients);
IngredientCount.set(4, IngredientCount.get(4) + newIngredients);
}
}
public void Bake(int cookiesToBake, int CookieTypeIndex){
if(IngredientCount.size() == 0){
System.out.println("No Ingredients");
}
else if(IngredientCount.get(0) > cookiesToBake){
IngredientCount.set(0, IngredientCount.get(0) - cookiesToBake);
IngredientCount.set(1, IngredientCount.get(1) - cookiesToBake);
IngredientCount.set(2, IngredientCount.get(2) - cookiesToBake);
if(CookieTypeIndex == 0){
IngredientCount.set(3, IngredientCount.get(3) - cookiesToBake);
}
else if(CookieTypeIndex == 1){
IngredientCount.set(4, IngredientCount.get(4) - cookiesToBake);
}else if(CookieTypeIndex == 2){
IngredientCount.set(3, IngredientCount.get(3) - cookiesToBake);
IngredientCount.set(4, IngredientCount.get(4) - cookiesToBake);
}
TotalCookies[CookieTypeIndex] = TotalCookies[CookieTypeIndex] + cookiesToBake;
}
else{
System.out.println("Not Enough Ingredients To Bake");
}
}
public void ListCookiesInStock(){
for(var i=0; i<TotalCookies.length;i++){
if(TotalCookies[i] !=0){
System.out.println("We currently have " + CookieTypes[i] + " in stock.");
}
}
}
public void getNumberofCookieType(int CookieTypeIndex){
System.out.println("There are " + TotalCookies[CookieTypeIndex] + " " + CookieTypes[CookieTypeIndex] + " cookies.");
}
public void Sell(int CustomerBought, double customerPayment, boolean Open, int CookieTypeIndex){
if(!Open){
System.out.println("I'm sorry, we are closed.");
}
else if(CustomerBought > TotalCookies[CookieTypeIndex]){
System.out.println("I'm sorry, we don't have that many cookies currently in stock.");
}
else if(customerPayment >= (inventoryPrice + tax)* CustomerBought ){
TotalCookies[CookieTypeIndex] = TotalCookies[CookieTypeIndex] - CustomerBought;
double newMoney = TotalBalance + (inventoryPrice *CustomerBought);
TotalBalance = newMoney;
System.out.println("Your change is $" + roundAvoid((customerPayment -((inventoryPrice + tax) *CustomerBought) ), 2));
}else{System.out.println("I'm sorry, this is not enough money for what you asked for.");}
}
public double calculateTax(double PricetoCalculate){
double taxtoCalculate = PricetoCalculate * 0.08;
tax = taxtoCalculate;
return tax;
}
public static double roundAvoid(double value, int places) {
double scale = Math.pow(10, places);
return Math.round(value * scale) / scale;
}
public void Advertise(String CookieType){
if(CookieType == "chocolate chip"){
System.out.println("Eat more " + CookieTypes[0].toUpperCase().charAt(CookieTypes[0].indexOf("chocolate")) + CookieTypes[0].toUpperCase().charAt(CookieTypes[0].indexOf("chip")) + " Cookies!");}
else if(CookieType == "peanut butter"){
System.out.println("Eat more " + CookieTypes[1].toUpperCase().charAt(CookieTypes[1].indexOf("pean")) + CookieTypes[1].toUpperCase().charAt(CookieTypes[1].indexOf("butt")) + " Cookies!");}
else if(CookieType == "peanut butter chocolate"){
System.out.println("Eat more " + CookieTypes[2].toUpperCase().charAt(CookieTypes[2].indexOf("pean")) + CookieTypes[2].toUpperCase().charAt(CookieTypes[2].indexOf("butt")) +
CookieTypes[2].toUpperCase().charAt(CookieTypes[2].indexOf("choc")) + " Cookies!");}
}
// constructor method
public Store(String product, double price, String address) {
inventoryPrice = price;
productType = product;
Streetaddress = address;
}
// main method
public static void main(String[] args) {
Store cookieShop = new Store("cookies", 3.75, "542 Sesame Street");
boolean LessThan5Dollars = cookieShop.inventoryPrice < 5;
System.out.println("Is the cookie less than 5 dollars?: " + LessThan5Dollars);
cookieShop.calculateTax(cookieShop.inventoryPrice);
System.out.println("In my store I sell " + cookieShop.productType + " that costs $" +
cookieShop.inventoryPrice +
" We are located at " + cookieShop.Streetaddress);
cookieShop.ListCookiesInStock();
cookieShop.BuyIngredients(100, 10);
cookieShop.Bake(20, 0);
cookieShop.BuyIngredients(100, 10);
System.out.println("These are the number of each Ingredient: " + cookieShop.IngredientCount);
System.out.println("These are my cookie ingredients" + cookieShop.Ingredients);
cookieShop.Sell(5, 25, true, 0);
for(int item : cookieShop.TotalCookies){
System.out.println(item);
}
cookieShop.getNumberofCookieType(0);
cookieShop.Advertise("chocolate chip");
System.out.println("My Balance is $" + cookieShop.TotalBalance);
}
}