├── Coca-Cola-hug-machine
├── Coca-Cola-hug-machine.csproj
├── CocaColaProduct.cs
├── Program.cs
└── VendingMachine.cs
├── Coca-Cola-hug-machine.sln
├── .gitignore
└── README.md
/Coca-Cola-hug-machine/Coca-Cola-hug-machine.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | netcoreapp2.2
6 | Coca_Cola_hug_machine
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/Coca-Cola-hug-machine.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 15
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Coca-Cola-hug-machine", "Coca-Cola-hug-machine\Coca-Cola-hug-machine.csproj", "{5A8BF920-2E7C-4355-A21C-A5E852EF058C}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|Any CPU = Debug|Any CPU
9 | Release|Any CPU = Release|Any CPU
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {5A8BF920-2E7C-4355-A21C-A5E852EF058C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
13 | {5A8BF920-2E7C-4355-A21C-A5E852EF058C}.Debug|Any CPU.Build.0 = Debug|Any CPU
14 | {5A8BF920-2E7C-4355-A21C-A5E852EF058C}.Release|Any CPU.ActiveCfg = Release|Any CPU
15 | {5A8BF920-2E7C-4355-A21C-A5E852EF058C}.Release|Any CPU.Build.0 = Release|Any CPU
16 | EndGlobalSection
17 | EndGlobal
18 |
--------------------------------------------------------------------------------
/Coca-Cola-hug-machine/CocaColaProduct.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace Coca_Cola_hug_machine
3 | {
4 | public class CocaColaProduct
5 | {
6 | public string Code { get; set; }
7 | public string Name { get; set; }
8 | public string Category { get; set; }
9 | public int QTY { get; set; }
10 | public double Price { get; set; }
11 | public double Balance { get; set; }
12 |
13 | public CocaColaProduct()
14 | {
15 | }
16 |
17 | public void SumQty(int qty)
18 | {
19 | this.QTY += qty;
20 | }
21 |
22 | public bool ValidateQTY()
23 | {
24 | if (this.QTY > 0)
25 | {
26 | return true;
27 | }
28 | return false;
29 | }
30 |
31 | public bool ValidatePrice(double payment)
32 | {
33 | if (this.Price <= payment)
34 | {
35 | this.Balance = payment - this.Price;
36 | return true;
37 | }
38 | return false;
39 | }
40 |
41 | public void SubstrProduct()
42 | {
43 | this.QTY--;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/Coca-Cola-hug-machine/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Coca_Cola_hug_machine
4 | {
5 | class Program
6 | {
7 | static void Main(string[] args)
8 | {
9 | VendingMachine vm = new VendingMachine();
10 | CocaColaProduct prod = new CocaColaProduct();
11 | Console.WriteLine("Welcome to Coca-Cola Hug Machine");
12 | while (true)
13 | {
14 | Console.WriteLine(vm.ListProduct());
15 | Console.WriteLine("1. ADD PRODUCT");
16 | Console.WriteLine("2. UPDATE PRODUCT");
17 | Console.WriteLine("3. DELETE PRODUCT");
18 | Console.WriteLine("4. BUY PRODUCT");
19 |
20 | string option = Console.ReadLine();
21 | switch (option)
22 | {
23 | case "1":
24 | Console.Write("Enter code: ");
25 | prod.Code = Console.ReadLine();
26 |
27 | Console.Write("Enter name: ");
28 | prod.Name = Console.ReadLine();
29 |
30 | Console.Write("Enter category: ");
31 | prod.Category = Console.ReadLine();
32 |
33 | Console.Write("Enter quantity: ");
34 | prod.QTY = Convert.ToInt32(Console.ReadLine());
35 |
36 | Console.Write("Enter price: ");
37 | prod.Price = Convert.ToDouble(Console.ReadLine());
38 |
39 | vm.AddProduct(prod);
40 |
41 | break;
42 | case "2":
43 | Console.Write("Enter code: ");
44 | string code = Console.ReadLine();
45 |
46 | Console.Write("Update name: ");
47 | prod.Name = Console.ReadLine();
48 |
49 | Console.Write("Update category: ");
50 | prod.Category = Console.ReadLine();
51 |
52 | Console.Write("Update price: ");
53 | prod.Price = Convert.ToDouble(Console.ReadLine());
54 |
55 | vm.UpdProduct(code,prod);
56 |
57 | break;
58 | case "3":
59 | Console.Write("Enter code: ");
60 | string code_deleted = Console.ReadLine();
61 |
62 | vm.DeleteProduct(code_deleted);
63 | break;
64 | case "4":
65 | Console.Write("Enter code: ");
66 | string code_order = Console.ReadLine();
67 | Console.Write("Enter coins $USD(100-50-20-10): ");
68 | vm.Payment = Console.ReadLine();
69 | CocaColaProduct prod_buy = vm.Order(code_order);
70 | if (prod_buy == null)
71 | {
72 | Console.WriteLine("There is no required product!");
73 | }
74 | else
75 | {
76 | Console.WriteLine("You are enjoying a delicious {0} with code {1} and its balance is ${2}", prod_buy.Name, prod_buy.Code, prod_buy.Balance);
77 | }
78 | break;
79 | }
80 |
81 | Console.Write("Do you want to continue Y/N?: ");
82 | if (Console.ReadLine() == "N")
83 | {
84 | break;
85 | }
86 | }
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/Coca-Cola-hug-machine/VendingMachine.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Coca_Cola_hug_machine
5 | {
6 | public class VendingMachine
7 | {
8 | public List Products { get; set; }
9 | public string Payment { get; set; }
10 |
11 | public VendingMachine()
12 | {
13 | this.Products = new List();
14 | CocaColaProduct cocaCola = new CocaColaProduct();
15 | //categories: popular,diet,cool
16 | cocaCola.Code = "P-123";
17 | cocaCola.Name = "Coca-Cola";
18 | cocaCola.Category = "POPULAR";
19 | cocaCola.QTY = 500;
20 | cocaCola.Price = 5.25;
21 |
22 | CocaColaProduct dietCoke = new CocaColaProduct();
23 | dietCoke.Code = "D-456";
24 | dietCoke.Name = "Diet Coke";
25 | dietCoke.Category = "DIET";
26 | dietCoke.QTY = 250;
27 | dietCoke.Price = 6.75;
28 |
29 | CocaColaProduct sprite = new CocaColaProduct();
30 | sprite.Code = "D-789";
31 | sprite.Name = "Sprite";
32 | sprite.Category = "COOL";
33 | sprite.QTY = 150;
34 | sprite.Price = 7.55;
35 |
36 | this.Products.Add(cocaCola);
37 | this.Products.Add(dietCoke);
38 | this.Products.Add(sprite);
39 | }
40 |
41 | public int ValidateProduct(string code)
42 | {
43 | int pos = -1;
44 | for (int i = 0; i < this.Products.Count; i++)
45 | {
46 | if (this.Products[i].Code == code)
47 | {
48 | pos = i;
49 | }
50 | }
51 | return pos;
52 | }
53 |
54 |
55 | public bool AddProduct(CocaColaProduct product)
56 | {
57 | int position = this.ValidateProduct(product.Code);
58 | if (position >= 0)
59 | {
60 | this.Products[position].SumQty(product.QTY);
61 | }
62 | else
63 | {
64 | this.Products.Add(product);
65 | }
66 | return true;
67 | }
68 |
69 | public bool UpdProduct(string code, CocaColaProduct product)
70 | {
71 | int position = this.ValidateProduct(code);
72 | if (position >= 0)
73 | {
74 | this.Products[position].Name = product.Name;
75 | this.Products[position].Category = product.Category;
76 | this.Products[position].Price = product.Price;
77 | }
78 | else
79 | {
80 | this.Products.Add(product);
81 | }
82 | return true;
83 | }
84 |
85 | public bool DeleteProduct(string code)
86 | {
87 | int position = this.ValidateProduct(code);
88 | if (position >= 0)
89 | {
90 | this.Products.RemoveAt(position);
91 | return true;
92 | }
93 |
94 | return false;
95 | }
96 |
97 | public double ValidateCoins(string[] coins)
98 | {
99 | double total = 0;
100 | foreach (string item in coins)
101 | {
102 | try
103 | {
104 | total += float.Parse(item);
105 | }
106 | catch (Exception ex)
107 | {
108 | Console.Write(ex);
109 | }
110 | }
111 | return total;
112 | }
113 |
114 | //100-50-20-10 money to pay
115 | public CocaColaProduct Order(string code)
116 | {
117 | int pos = this.ValidateProduct(code);
118 | if (pos > 0)
119 | {
120 | if (this.Products[pos].ValidateQTY())
121 | {
122 | string[] coins = this.Payment.Split('-');
123 | double total = this.ValidateCoins(coins);
124 | if (this.Products[pos].ValidatePrice(total))
125 | {
126 | this.Products[pos].SubstrProduct();
127 | return this.Products[pos];
128 | }
129 | }
130 | }
131 | return null;
132 | }
133 |
134 | public string ListProduct()
135 | {
136 | string list = "";
137 | foreach (CocaColaProduct item in this.Products)
138 | {
139 | list += item.Code+" "+item.Name+" "+item.Category+" "+item.QTY+" "+item.Price+"\n";
140 | }
141 | return list;
142 | }
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/csharp
3 | # Edit at https://www.gitignore.io/?templates=csharp
4 |
5 | ### Csharp ###
6 | ## Ignore Visual Studio temporary files, build results, and
7 | ## files generated by popular Visual Studio add-ons.
8 | ##
9 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
10 |
11 | # User-specific files
12 | *.rsuser
13 | *.suo
14 | *.user
15 | *.userosscache
16 | *.sln.docstates
17 |
18 | # User-specific files (MonoDevelop/Xamarin Studio)
19 | *.userprefs
20 |
21 | # Mono auto generated files
22 | mono_crash.*
23 |
24 | # Build results
25 | [Dd]ebug/
26 | [Dd]ebugPublic/
27 | [Rr]elease/
28 | [Rr]eleases/
29 | x64/
30 | x86/
31 | [Aa][Rr][Mm]/
32 | [Aa][Rr][Mm]64/
33 | bld/
34 | [Bb]in/
35 | [Oo]bj/
36 | [Ll]og/
37 |
38 | # Visual Studio 2015/2017 cache/options directory
39 | .vs/
40 | # Uncomment if you have tasks that create the project's static files in wwwroot
41 | #wwwroot/
42 |
43 | # Visual Studio 2017 auto generated files
44 | Generated\ Files/
45 |
46 | # MSTest test Results
47 | [Tt]est[Rr]esult*/
48 | [Bb]uild[Ll]og.*
49 |
50 | # NUnit
51 | *.VisualState.xml
52 | TestResult.xml
53 | nunit-*.xml
54 |
55 | # Build Results of an ATL Project
56 | [Dd]ebugPS/
57 | [Rr]eleasePS/
58 | dlldata.c
59 |
60 | # Benchmark Results
61 | BenchmarkDotNet.Artifacts/
62 |
63 | # .NET Core
64 | project.lock.json
65 | project.fragment.lock.json
66 | artifacts/
67 |
68 | # StyleCop
69 | StyleCopReport.xml
70 |
71 | # Files built by Visual Studio
72 | *_i.c
73 | *_p.c
74 | *_h.h
75 | *.ilk
76 | *.obj
77 | *.iobj
78 | *.pch
79 | *.pdb
80 | *.ipdb
81 | *.pgc
82 | *.pgd
83 | *.rsp
84 | *.sbr
85 | *.tlb
86 | *.tli
87 | *.tlh
88 | *.tmp
89 | *.tmp_proj
90 | *_wpftmp.csproj
91 | *.log
92 | *.vspscc
93 | *.vssscc
94 | .builds
95 | *.pidb
96 | *.svclog
97 | *.scc
98 |
99 | # Chutzpah Test files
100 | _Chutzpah*
101 |
102 | # Visual C++ cache files
103 | ipch/
104 | *.aps
105 | *.ncb
106 | *.opendb
107 | *.opensdf
108 | *.sdf
109 | *.cachefile
110 | *.VC.db
111 | *.VC.VC.opendb
112 |
113 | # Visual Studio profiler
114 | *.psess
115 | *.vsp
116 | *.vspx
117 | *.sap
118 |
119 | # Visual Studio Trace Files
120 | *.e2e
121 |
122 | # TFS 2012 Local Workspace
123 | $tf/
124 |
125 | # Guidance Automation Toolkit
126 | *.gpState
127 |
128 | # ReSharper is a .NET coding add-in
129 | _ReSharper*/
130 | *.[Rr]e[Ss]harper
131 | *.DotSettings.user
132 |
133 | # JustCode is a .NET coding add-in
134 | .JustCode
135 |
136 | # TeamCity is a build add-in
137 | _TeamCity*
138 |
139 | # DotCover is a Code Coverage Tool
140 | *.dotCover
141 |
142 | # AxoCover is a Code Coverage Tool
143 | .axoCover/*
144 | !.axoCover/settings.json
145 |
146 | # Visual Studio code coverage results
147 | *.coverage
148 | *.coveragexml
149 |
150 | # NCrunch
151 | _NCrunch_*
152 | .*crunch*.local.xml
153 | nCrunchTemp_*
154 |
155 | # MightyMoose
156 | *.mm.*
157 | AutoTest.Net/
158 |
159 | # Web workbench (sass)
160 | .sass-cache/
161 |
162 | # Installshield output folder
163 | [Ee]xpress/
164 |
165 | # DocProject is a documentation generator add-in
166 | DocProject/buildhelp/
167 | DocProject/Help/*.HxT
168 | DocProject/Help/*.HxC
169 | DocProject/Help/*.hhc
170 | DocProject/Help/*.hhk
171 | DocProject/Help/*.hhp
172 | DocProject/Help/Html2
173 | DocProject/Help/html
174 |
175 | # Click-Once directory
176 | publish/
177 |
178 | # Publish Web Output
179 | *.[Pp]ublish.xml
180 | *.azurePubxml
181 | # Note: Comment the next line if you want to checkin your web deploy settings,
182 | # but database connection strings (with potential passwords) will be unencrypted
183 | *.pubxml
184 | *.publishproj
185 |
186 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
187 | # checkin your Azure Web App publish settings, but sensitive information contained
188 | # in these scripts will be unencrypted
189 | PublishScripts/
190 |
191 | # NuGet Packages
192 | *.nupkg
193 | # NuGet Symbol Packages
194 | *.snupkg
195 | # The packages folder can be ignored because of Package Restore
196 | **/[Pp]ackages/*
197 | # except build/, which is used as an MSBuild target.
198 | !**/[Pp]ackages/build/
199 | # Uncomment if necessary however generally it will be regenerated when needed
200 | #!**/[Pp]ackages/repositories.config
201 | # NuGet v3's project.json files produces more ignorable files
202 | *.nuget.props
203 | *.nuget.targets
204 |
205 | # Microsoft Azure Build Output
206 | csx/
207 | *.build.csdef
208 |
209 | # Microsoft Azure Emulator
210 | ecf/
211 | rcf/
212 |
213 | # Windows Store app package directories and files
214 | AppPackages/
215 | BundleArtifacts/
216 | Package.StoreAssociation.xml
217 | _pkginfo.txt
218 | *.appx
219 | *.appxbundle
220 | *.appxupload
221 |
222 | # Visual Studio cache files
223 | # files ending in .cache can be ignored
224 | *.[Cc]ache
225 | # but keep track of directories ending in .cache
226 | !?*.[Cc]ache/
227 |
228 | # Others
229 | ClientBin/
230 | ~$*
231 | *~
232 | *.dbmdl
233 | *.dbproj.schemaview
234 | *.jfm
235 | *.pfx
236 | *.publishsettings
237 | orleans.codegen.cs
238 |
239 | # Including strong name files can present a security risk
240 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
241 | #*.snk
242 |
243 | # Since there are multiple workflows, uncomment next line to ignore bower_components
244 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
245 | #bower_components/
246 |
247 | # RIA/Silverlight projects
248 | Generated_Code/
249 |
250 | # Backup & report files from converting an old project file
251 | # to a newer Visual Studio version. Backup files are not needed,
252 | # because we have git ;-)
253 | _UpgradeReport_Files/
254 | Backup*/
255 | UpgradeLog*.XML
256 | UpgradeLog*.htm
257 | ServiceFabricBackup/
258 | *.rptproj.bak
259 |
260 | # SQL Server files
261 | *.mdf
262 | *.ldf
263 | *.ndf
264 |
265 | # Business Intelligence projects
266 | *.rdl.data
267 | *.bim.layout
268 | *.bim_*.settings
269 | *.rptproj.rsuser
270 | *- [Bb]ackup.rdl
271 | *- [Bb]ackup ([0-9]).rdl
272 | *- [Bb]ackup ([0-9][0-9]).rdl
273 |
274 | # Microsoft Fakes
275 | FakesAssemblies/
276 |
277 | # GhostDoc plugin setting file
278 | *.GhostDoc.xml
279 |
280 | # Node.js Tools for Visual Studio
281 | .ntvs_analysis.dat
282 | node_modules/
283 |
284 | # Visual Studio 6 build log
285 | *.plg
286 |
287 | # Visual Studio 6 workspace options file
288 | *.opt
289 |
290 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
291 | *.vbw
292 |
293 | # Visual Studio LightSwitch build output
294 | **/*.HTMLClient/GeneratedArtifacts
295 | **/*.DesktopClient/GeneratedArtifacts
296 | **/*.DesktopClient/ModelManifest.xml
297 | **/*.Server/GeneratedArtifacts
298 | **/*.Server/ModelManifest.xml
299 | _Pvt_Extensions
300 |
301 | # Paket dependency manager
302 | .paket/paket.exe
303 | paket-files/
304 |
305 | # FAKE - F# Make
306 | .fake/
307 |
308 | # CodeRush personal settings
309 | .cr/personal
310 |
311 | # Python Tools for Visual Studio (PTVS)
312 | __pycache__/
313 | *.pyc
314 |
315 | # Cake - Uncomment if you are using it
316 | # tools/**
317 | # !tools/packages.config
318 |
319 | # Tabs Studio
320 | *.tss
321 |
322 | # Telerik's JustMock configuration file
323 | *.jmconfig
324 |
325 | # BizTalk build output
326 | *.btp.cs
327 | *.btm.cs
328 | *.odx.cs
329 | *.xsd.cs
330 |
331 | # OpenCover UI analysis results
332 | OpenCover/
333 |
334 | # Azure Stream Analytics local run output
335 | ASALocalRun/
336 |
337 | # MSBuild Binary and Structured Log
338 | *.binlog
339 |
340 | # NVidia Nsight GPU debugger configuration file
341 | *.nvuser
342 |
343 | # MFractors (Xamarin productivity tool) working folder
344 | .mfractor/
345 |
346 | # Local History for Visual Studio
347 | .localhistory/
348 |
349 | # BeatPulse healthcheck temp database
350 | healthchecksdb
351 |
352 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
353 | MigrationBackup/
354 |
355 | # End of https://www.gitignore.io/api/csharp
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Coca-Cola-popular-drink
2 |
3 | ## Description
4 |
5 | This repository is a Software of Console with C# etc.
6 |
7 | ## Installation
8 |
9 | Using CSharp preferably.
10 |
11 | ## Development
12 |
13 | Using MonoDevelop.
14 |
15 | ## Usage
16 |
17 | ```html
18 | $ git clone https://github.com/DanielArturoAlejoAlvarez/Coca-Cola-popular-drink[NAME APP]
19 |
20 | $ npm install
21 |
22 | ```
23 |
24 | Follow the following steps and you're good to go! Important:
25 |
26 | 
27 |
28 | ## Coding
29 |
30 | ### Controllers
31 |
32 | ```cs
33 | ...
34 | public class VendingMachine
35 | {
36 | public List Products { get; set; }
37 | public string Payment { get; set; }
38 |
39 | public VendingMachine()
40 | {
41 | this.Products = new List();
42 | CocaColaProduct cocaCola = new CocaColaProduct();
43 | //categories: popular,diet,cool
44 | cocaCola.Code = "P-123";
45 | cocaCola.Name = "Coca-Cola";
46 | cocaCola.Category = "POPULAR";
47 | cocaCola.QTY = 500;
48 | cocaCola.Price = 5.25;
49 |
50 | CocaColaProduct dietCoke = new CocaColaProduct();
51 | dietCoke.Code = "D-456";
52 | dietCoke.Name = "Diet Coke";
53 | dietCoke.Category = "DIET";
54 | dietCoke.QTY = 250;
55 | dietCoke.Price = 6.75;
56 |
57 | CocaColaProduct sprite = new CocaColaProduct();
58 | sprite.Code = "D-789";
59 | sprite.Name = "Sprite";
60 | sprite.Category = "COOL";
61 | sprite.QTY = 150;
62 | sprite.Price = 7.55;
63 |
64 | this.Products.Add(cocaCola);
65 | this.Products.Add(dietCoke);
66 | this.Products.Add(sprite);
67 | }
68 |
69 | public int ValidateProduct(string code)
70 | {
71 | int pos = -1;
72 | for (int i = 0; i < this.Products.Count; i++)
73 | {
74 | if (this.Products[i].Code == code)
75 | {
76 | pos = i;
77 | }
78 | }
79 | return pos;
80 | }
81 |
82 |
83 | public bool AddProduct(CocaColaProduct product)
84 | {
85 | int position = this.ValidateProduct(product.Code);
86 | if (position >= 0)
87 | {
88 | this.Products[position].SumQty(product.QTY);
89 | }
90 | else
91 | {
92 | this.Products.Add(product);
93 | }
94 | return true;
95 | }
96 |
97 | public bool UpdProduct(string code, CocaColaProduct product)
98 | {
99 | int position = this.ValidateProduct(code);
100 | if (position >= 0)
101 | {
102 | this.Products[position].Name = product.Name;
103 | this.Products[position].Category = product.Category;
104 | this.Products[position].Price = product.Price;
105 | }
106 | else
107 | {
108 | this.Products.Add(product);
109 | }
110 | return true;
111 | }
112 |
113 | public bool DeleteProduct(string code)
114 | {
115 | int position = this.ValidateProduct(code);
116 | if (position >= 0)
117 | {
118 | this.Products.RemoveAt(position);
119 | return true;
120 | }
121 |
122 | return false;
123 | }
124 |
125 | public double ValidateCoins(string[] coins)
126 | {
127 | double total = 0;
128 | foreach (string item in coins)
129 | {
130 | try
131 | {
132 | total += float.Parse(item);
133 | }
134 | catch (Exception ex)
135 | {
136 | Console.Write(ex);
137 | }
138 | }
139 | return total;
140 | }
141 |
142 | //100-50-20-10 money to pay
143 | public CocaColaProduct Order(string code)
144 | {
145 | int pos = this.ValidateProduct(code);
146 | if (pos > 0)
147 | {
148 | if (this.Products[pos].ValidateQTY())
149 | {
150 | string[] coins = this.Payment.Split('-');
151 | double total = this.ValidateCoins(coins);
152 | if (this.Products[pos].ValidatePrice(total))
153 | {
154 | this.Products[pos].SubstrProduct();
155 | return this.Products[pos];
156 | }
157 | }
158 | }
159 | return null;
160 | }
161 |
162 | public string ListProduct()
163 | {
164 | string list = "";
165 | foreach (CocaColaProduct item in this.Products)
166 | {
167 | list += item.Code+" "+item.Name+" "+item.Category+" "+item.QTY+" "+item.Price+"\n";
168 | }
169 | return list;
170 | }
171 | }
172 | ...
173 | ```
174 |
175 | ### Models
176 |
177 | ```cs
178 | ...
179 | public class CocaColaProduct
180 | {
181 | public string Code { get; set; }
182 | public string Name { get; set; }
183 | public string Category { get; set; }
184 | public int QTY { get; set; }
185 | public double Price { get; set; }
186 | public double Balance { get; set; }
187 |
188 | public CocaColaProduct()
189 | {
190 | }
191 |
192 | public void SumQty(int qty)
193 | {
194 | this.QTY += qty;
195 | }
196 |
197 | public bool ValidateQTY()
198 | {
199 | if (this.QTY > 0)
200 | {
201 | return true;
202 | }
203 | return false;
204 | }
205 |
206 | public bool ValidatePrice(double payment)
207 | {
208 | if (this.Price <= payment)
209 | {
210 | this.Balance = payment - this.Price;
211 | return true;
212 | }
213 | return false;
214 | }
215 |
216 | public void SubstrProduct()
217 | {
218 | this.QTY--;
219 | }
220 | }
221 | ...
222 | ```
223 |
224 | ### Views
225 |
226 | ```cs
227 | ...
228 | class Program
229 | {
230 | static void Main(string[] args)
231 | {
232 | VendingMachine vm = new VendingMachine();
233 | CocaColaProduct prod = new CocaColaProduct();
234 | Console.WriteLine("Welcome to Coca-Cola Hug Machine");
235 | while (true)
236 | {
237 | Console.WriteLine(vm.ListProduct());
238 | Console.WriteLine("1. ADD PRODUCT");
239 | Console.WriteLine("2. UPDATE PRODUCT");
240 | Console.WriteLine("3. DELETE PRODUCT");
241 | Console.WriteLine("4. BUY PRODUCT");
242 |
243 | string option = Console.ReadLine();
244 | switch (option)
245 | {
246 | case "1":
247 | Console.Write("Enter code: ");
248 | prod.Code = Console.ReadLine();
249 |
250 | Console.Write("Enter name: ");
251 | prod.Name = Console.ReadLine();
252 |
253 | Console.Write("Enter category: ");
254 | prod.Category = Console.ReadLine();
255 |
256 | Console.Write("Enter quantity: ");
257 | prod.QTY = Convert.ToInt32(Console.ReadLine());
258 |
259 | Console.Write("Enter price: ");
260 | prod.Price = Convert.ToDouble(Console.ReadLine());
261 |
262 | vm.AddProduct(prod);
263 |
264 | break;
265 | case "2":
266 | Console.Write("Enter code: ");
267 | string code = Console.ReadLine();
268 |
269 | Console.Write("Update name: ");
270 | prod.Name = Console.ReadLine();
271 |
272 | Console.Write("Update category: ");
273 | prod.Category = Console.ReadLine();
274 |
275 | Console.Write("Update price: ");
276 | prod.Price = Convert.ToDouble(Console.ReadLine());
277 |
278 | vm.UpdProduct(code,prod);
279 |
280 | break;
281 | case "3":
282 | Console.Write("Enter code: ");
283 | string code_deleted = Console.ReadLine();
284 |
285 | vm.DeleteProduct(code_deleted);
286 | break;
287 | case "4":
288 | Console.Write("Enter code: ");
289 | string code_order = Console.ReadLine();
290 | Console.Write("Enter coins $USD(100-50-20-10): ");
291 | vm.Payment = Console.ReadLine();
292 | CocaColaProduct prod_buy = vm.Order(code_order);
293 | if (prod_buy == null)
294 | {
295 | Console.WriteLine("There is no required product!");
296 | }
297 | else
298 | {
299 | Console.WriteLine("You are enjoying a delicious {0} with code {1} and its balance is ${2}", prod_buy.Name, prod_buy.Code, prod_buy.Balance);
300 | }
301 | break;
302 | }
303 |
304 | Console.Write("Do you want to continue Y/N?: ");
305 | if (Console.ReadLine() == "N")
306 | {
307 | break;
308 | }
309 | }
310 | }
311 | }
312 | ...
313 | ```
314 |
315 | ## Contributing
316 |
317 | Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/Coca-Cola-popular-drink. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
318 |
319 | ## License
320 |
321 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
322 |
323 | ```
324 |
325 | ```
326 |
--------------------------------------------------------------------------------