-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
137 lines (118 loc) · 5.73 KB
/
Copy pathProgram.cs
File metadata and controls
137 lines (118 loc) · 5.73 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
using Mission3;
internal class Program
{
public static void Main(string[] args)
{
bool programRunning = true;
List<FoodItem> foodItems = new List<FoodItem>();
while (programRunning)
{
Console.WriteLine("\nHello, welcome to your Food Bank Inventory!\n" +
"Below are the menu options:");
Console.WriteLine("1. Add a food item\n" +
"2. Delete a food item\n" +
"3. Print list of current food items\n" +
"4. Exit");
Console.Write("Please select an option by entering a number (e.g. '3'): ");
string choice = Console.ReadLine();
switch (choice)
{
// ADD FOOD ITEM CASE
case "1":
Console.Write("\n\n\n\nAdd Food Item selected.\n" +
"Please enter the name of the food item you would like to add: ");
string name = Console.ReadLine();
Console.WriteLine($"Adding {name}...");
Console.Write($"What food category does {name} belong to?: ");
string category = Console.ReadLine();
int quantity;
while (true)
{
Console.Write($"How many {name}(s) would you like to add? (Whole numbers only e.g. '7'): ");
if (int.TryParse(Console.ReadLine(), out quantity) && quantity > 0)
{
break;
}
Console.WriteLine("Invalid input. Please enter a positive whole number.");
}
DateTime expirationDate;
while (true)
{
Console.Write($"Finally, when do your {quantity} {name}(s) expire? (yyyy-mm-dd): ");
if (DateTime.TryParse(Console.ReadLine(), out expirationDate))
{
break;
}
Console.WriteLine("Invalid date format. Please enter the date in yyyy-mm-dd format.");
}
FoodItem newItem = new FoodItem(name, category, quantity, expirationDate);
foodItems.Add(newItem);
Console.WriteLine($"\n\nSuccessfully added {quantity} {name}(s) to the {category} inventory. Expiration Date: {expirationDate:yyyy-mm-dd}" +
"\n\nTaking you back to the main menu...");
break;
// DELETE FOOD ITEM CASE
case "2":
Console.WriteLine("\n\n\n\nDelete Food Item selected.\n");
if (foodItems.Count == 0)
{
Console.WriteLine("There are no food items in your inventory.");
break;
}
Console.WriteLine("\nCurrent Food Items:");
for (int i = 0; i < foodItems.Count; i++)
{
FoodItem item = foodItems[i];
Console.WriteLine($"{i + 1}. {item.name} - qty: {item.quantity} | category: {item.category} | (Expires: {item.expirationDate:yyyy-MM-dd})");
}
// Prompt the user to select an item by index
Console.Write("\nEnter the number of the food item you want to delete: ");
if (int.TryParse(Console.ReadLine(), out int index) && index > 0 && index <= foodItems.Count)
{
// Remove the selected item
FoodItem removedItem = foodItems[index - 1];
foodItems.RemoveAt(index - 1);
Console.WriteLine($"Successfully removed {removedItem.name} from the inventory.");
}
else
{
Console.WriteLine("Invalid selection. Please try again.");
}
break;
// PRINT LIST CASE
case "3":
Console.WriteLine("\n\n\n\nCurrent Food Items:\n");
if (foodItems.Count == 0)
{
Console.WriteLine("There are no food items in your inventory.");
}
else
{
for (int i = 0; i < foodItems.Count; i++)
{
FoodItem item = foodItems[i];
Console.WriteLine($"{i + 1}. {item.name} - qty: {item.quantity} | category: {item.category} | Expires: {item.expirationDate:yyyy-mm-dd}");
}
}
Console.Write("\nWould you like to go back to the main menu? (y for yes /n to exit): ");
string answer = Console.ReadLine();
if (answer == "y")
{
break;
}
else if (answer == "n")
{
programRunning = false;
}
break;
// EXIT CASE
case "4":
Console.WriteLine("\n\n\n\nExiting program...\n");
programRunning = false;
break;
default:
Console.WriteLine("\n\n\n\nInvalid choice. Please try again.\n");
break;
}
}
}
}