-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
218 lines (179 loc) · 8.33 KB
/
Program.cs
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using CarClassLibrary;
using System.ComponentModel.DataAnnotations;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
internal class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Write your name: ");
string name = Console.ReadLine();
Account acc = new Account(name, 100);
Console.WriteLine("Hello " + acc.UserName);
Console.WriteLine($"Account was created for {acc.UserName} with {acc.Balance} initial balance.\n");
Console.WriteLine("Welcome to the car store! First you must create some inventory.\n Than you may add some cars to the shopping cart. And then you can buy it ");
int action = chooseAction();
Store atb = new Store();
while (action != 0)
{
switch (action)
{
//add item to inventory
case 1:
String carMake = "";
String carModel = "";
Decimal carPrice = 0;
String carColor = "";
int carYear = 0;
Console.WriteLine("You chose to add car to inventory");
Console.WriteLine("(0) - add new car\n (1) - add used car");
int choice = int.Parse(Console.ReadLine());
Console.WriteLine("What is the car make?");
carMake = Console.ReadLine();
Console.WriteLine("What is the car model");
carModel = Console.ReadLine();
bool error2 = true;
while (error2)
{
try
{
Console.WriteLine("What is the price");
carPrice = int.Parse(Console.ReadLine());
error2 = false;
}
catch (FormatException)
{
Console.WriteLine("Write proper price");
error2 = true;
}
}
Console.WriteLine("What is the car color");
carColor = Console.ReadLine();
bool error1 = true;
while (error1)
{
try
{
Console.WriteLine("What is the car year");
carYear = int.Parse(Console.ReadLine());
error1 = false;
}
catch (FormatException)
{
Console.WriteLine("Write proper year");
error1 = true;
}
}
if (choice == 1)
{
bool error3 = true;
while (error3)
{
try
{
error3 = false;
Console.WriteLine("How many kilometers has this car traveled yet?");
decimal traveledKm = int.Parse(Console.ReadLine());
UsedCar newCar = new UsedCar(carMake, carModel, carPrice, carYear, carColor, traveledKm);
atb.CarList.Add(newCar);
}
catch (FormatException)
{
Console.WriteLine("Write kilometers properly");
error3 = true;
}
}
}
else
{
Car newCar = new Car(carMake, carModel, carPrice, carYear, carColor);
atb.CarList.Add(newCar);
}
atb.PrintCarList();
break;
case 2:
Console.WriteLine("You choose to add car to shopping cart");
atb.PrintCarList();
bool error = false;
while(error != true)
try
{
int carChosen = int.Parse(Console.ReadLine());
atb.ShoppingList.Add(atb.CarList[carChosen]);
atb.PrintShoppingList();
error= true;
}
catch(FormatException) {
Console.WriteLine("Write number of car");
error = false;
}
catch(ArgumentOutOfRangeException) {
Console.WriteLine("Choose car from the list");
error = false;
}
break;
//checkout
case 3:
atb.PrintShoppingList();
decimal sum = atb.Checkout();
Console.WriteLine("You sum is: " + sum);
Console.WriteLine("Your balance is: "+acc.Balance);
Console.WriteLine("Want to make a purchase? (1) YES (2) Make a deposit (3) Menu ");
int choice1 = int.Parse(Console.ReadLine());
if(choice1 == 1)
{
acc.BuyCar(atb.ShoppingList,atb.BoughtList, DateTime.Now);
Console.WriteLine("Thank you for buying!");
Console.WriteLine("You bought:");
atb.PrintBoughtList();
Console.WriteLine("Your balance is: " + acc.Balance);
Console.WriteLine(acc.GetHistory(atb.BoughtList));
}
else if(choice1 == 2) {
Console.WriteLine("What amount of money you want to deposit?");
decimal amount1 = int.Parse(Console.ReadLine());
acc.MakeDeposit(amount1, DateTime.Now);
Console.WriteLine("Your balcance is :" + acc.Balance);
}
break;
case 4:
Console.WriteLine("What amount of money you want to deposit?");
decimal amount = int.Parse(Console.ReadLine());
acc.MakeDeposit(amount, DateTime.Now);
Console.WriteLine("Your balcance is :" + acc.Balance);
break;
case 5:
atb.PrintCarList();
break;
case 6:
atb.PrintShoppingList();
break;
case 7:
Console.WriteLine(acc.GetHistory(atb.BoughtList));
break;
}
action = chooseAction();
}
}
public static int chooseAction()
{
bool error = false;
int choice = 0;
Console.WriteLine("Choose an action: (0) to quit\n (1) add a new car to inventory\n (2) add car to shopping list\n (3) to checkout(buy) \n(4) to make a deposit\n (5) to check inventory (6) to check shopping list (7) Purchase history ");
while (error != true && choice >= 0 && choice < 5)
{
try
{
choice = int.Parse(Console.ReadLine());
error = true;
}
catch (FormatException)
{
Console.WriteLine("Choose an action (0) to quit (1) add a new car to inventory (2) add car to shopping list (3) to checkout(buy)\n(4) to make a deposit\n (5) to check inventory (6) to check shopping list (7) Purchase history");
error = false;
}
}
return choice;
}
}