Skip to content

Commit c41f666

Browse files
authored
Add files via upload
1 parent 35928c2 commit c41f666

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Project : NW Stock [INPUT ENABLED]
2+
// Written by: Mason Z
3+
// Date: Sept 20, 2024
4+
// Description: Input enabled version. Coded in Programiz (Xcode has issues with allowing inputs in Console) Modifed Version of Original - NW Stock = New Wave Stock
5+
6+
import Foundation
7+
8+
// variables
9+
var stock = ["hard drives": 502, "software": 7, "wPhones": 24, "wPens": 700532]
10+
var exit = 1
11+
12+
// produce inventory at launch - starting screen
13+
print ("Product Quantity")
14+
for (product, quantity) in stock {
15+
print ("\(product) \(quantity)")
16+
}
17+
18+
print(" ")
19+
print("loading...")
20+
print(" ")
21+
print("welcome to new wave computer systems")
22+
print(" ")
23+
24+
while (exit == 1) {
25+
// menu
26+
print("************************************************************")
27+
print("1 - Add Product")
28+
print("2 - Add a Quantity to an Existing Product")
29+
print("3 - Remove a Quantity to an Existing Product")
30+
print("4 - Total # of Items in Stock")
31+
print("5 - All Items in Stock Report")
32+
print("0 - EXIT")
33+
print("************************************************************")
34+
35+
// input, prevent input of non integers w/ error
36+
var choice: Int = 0
37+
38+
if let c = Int(readLine()!) {
39+
choice = c
40+
}
41+
else {
42+
print(" ")
43+
print("ERROR 422: Invalid Input Type - Integers Only.")
44+
choice = 9
45+
}
46+
47+
print("")
48+
switch choice {
49+
case 0: // exit program
50+
print("exiting program...")
51+
exit = 0
52+
53+
case 1: // add product
54+
print("Enter Product Name")
55+
let productName: String = readLine() ?? "default"
56+
print("Enter the quantity of \(productName)")
57+
let productQuantity: Int = Int(readLine()!) ?? 0
58+
59+
if let quantity = stock[productName] {
60+
print("ERROR 403: \(productName) with a quantity of \(quantity) already exists.")
61+
}
62+
63+
else {
64+
stock[productName] = productQuantity
65+
}
66+
67+
68+
case 2: // add quantity to existing product
69+
print("Enter Product Name")
70+
let productName: String = readLine() ?? "default"
71+
print("Enter amount added")
72+
let addedQuantity: Int = Int(readLine()!) ?? 0
73+
74+
if let productQuantity = stock[productName] {
75+
stock[productName] = productQuantity + addedQuantity
76+
} else {
77+
print("ERROR 404: \(productName) doesn't exist.")
78+
}
79+
80+
81+
case 3: // remove quantity to existing product
82+
print("Enter Product Name")
83+
let productName: String = readLine() ?? "default"
84+
print("Enter amount removed")
85+
let removedQuantity: Int = Int(readLine()!) ?? 0
86+
87+
if let productQuantity = stock[productName]{
88+
stock[productName] = productQuantity - removedQuantity
89+
} else {
90+
print("ERROR 404: \(productName) doesn't exist.")
91+
}
92+
93+
94+
case 4: // Total # of Items in Stock
95+
var totalStock = 0
96+
97+
for quantity in stock.values {
98+
totalStock+=quantity
99+
}
100+
101+
print("Total Items in Stock = \(totalStock) ")
102+
103+
104+
case 5: // All items in Stock Report
105+
print ("Product Quantity")
106+
107+
for (product, quantity) in stock {
108+
print ("\(product) \(quantity)")
109+
}
110+
111+
112+
default: // ERROR 422: INVALID INPUT OPTION
113+
print("Please select an acceptable choice 1-5 or [0] to exit")
114+
}
115+
print(" ")
116+
}

0 commit comments

Comments
 (0)