From 2bdb39c4649f95f753b65c9a9756b02457fde370 Mon Sep 17 00:00:00 2001 From: Stephen Bierly Date: Mon, 27 Jan 2020 13:36:01 -0500 Subject: [PATCH 1/3] Creating the Project --- .gitignore | 5 ++ .vs/CashRegister/v16/.suo | Bin 0 -> 11264 bytes .vs/VSWorkspaceState.json | 6 ++ SWCashRegisterSB/App.config | 6 ++ SWCashRegisterSB/Program.cs | 15 +++++ SWCashRegisterSB/Properties/AssemblyInfo.cs | 36 ++++++++++++ SWCashRegisterSB/SWCashRegisterSB.csproj | 53 ++++++++++++++++++ ...gnTimeResolveAssemblyReferencesInput.cache | Bin 0 -> 6806 bytes ...shRegisterSB.csprojAssemblyReference.cache | Bin 0 -> 8212 bytes 9 files changed, 121 insertions(+) create mode 100644 .gitignore create mode 100644 .vs/CashRegister/v16/.suo create mode 100644 .vs/VSWorkspaceState.json create mode 100644 SWCashRegisterSB/App.config create mode 100644 SWCashRegisterSB/Program.cs create mode 100644 SWCashRegisterSB/Properties/AssemblyInfo.cs create mode 100644 SWCashRegisterSB/SWCashRegisterSB.csproj create mode 100644 SWCashRegisterSB/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache create mode 100644 SWCashRegisterSB/obj/Debug/SWCashRegisterSB.csprojAssemblyReference.cache diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..f97f6606 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +################################################################################ +# This .gitignore file was automatically created by Microsoft(R) Visual Studio. +################################################################################ + +/.vs/CashRegister/v16/Server/sqlite3 diff --git a/.vs/CashRegister/v16/.suo b/.vs/CashRegister/v16/.suo new file mode 100644 index 0000000000000000000000000000000000000000..e7d979440409956edfdf9d0ea1b12469945a4389 GIT binary patch literal 11264 zcmeI2Pj4GV7{=eE6ey)YC9|`LAirGtgrtQ(*-X5>0t6I_!ap1Dm^=sIK&D*x_k=^qZ>9+qXSNX@5O#qb+>c-u|}p)0=9R z_&W0V;O&Tq4VrF_g8g)L4|R7E@^l; z@FeyBr(ce@^xq4h*S{yJ|8Gc6OZ^uUL|#&#R~9eulw+G=>NTfIYm5cib1v%=@9>2b5TfDt#@q2Viya|xk#v@ zT|Y>Z1>zrM#*eftq?(I?HdWiUS$DmuS!}2^a>&g$zDN80UEyQPiDTHQ_P3p%_q~J{N=*CD_D#a3Z#=cE0lfLF;MZV;9kny!gzOcnzA>>MOzmZBxj14$PwYUAL>^ zzm^Tpiy!iTPME9W^oD-Kz1JMa*X)*_;%=Zp`$PeJ_(iM;rSUIn4(po3ZAIgCCyVSv zcRDBj6R#43=3PI2t(pv(#wQP0(+qYb0ZqBfLN_~GK>qQi_*Hy!fI1Wy$}NP`C9%?k~ArCrWPj z1o+>6`A_Ue3Q$X8V43B84+M^&7;k|oRxmW`VPCXA?;}PjP#~A4Z8oxFZmo4%JPby8T<1o zrJCXIz1CB9E$l=6F%hxAf^2L}+};$A`Kt%f*RDA4BOtR+^w&VF_QwZif&C!%aH}oA z%_`}1MPml=&)mAJ7U{XAB* z{~y)Aemgx~yg$A$T@Lg7kFiU7dO48Ro~8xB^5&y5|10yqP`dL;O_~4s{BJ=~%ZfZ! z`W$>BIEl#OX_50Ua%G=?9L)dtuZN*J|8?gX<@s;^{Fk#2fBuo)|NZmVp*jC`=MQgd zP1vCiypGba@{A1AkVKA + + + + + \ No newline at end of file diff --git a/SWCashRegisterSB/Program.cs b/SWCashRegisterSB/Program.cs new file mode 100644 index 00000000..0f897fd1 --- /dev/null +++ b/SWCashRegisterSB/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/SWCashRegisterSB/Properties/AssemblyInfo.cs b/SWCashRegisterSB/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..126fc933 --- /dev/null +++ b/SWCashRegisterSB/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("SWCashRegisterSB")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("SWCashRegisterSB")] +[assembly: AssemblyCopyright("Copyright © 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("5cf33ad0-25e5-4d11-954f-ad914ae820ac")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SWCashRegisterSB/SWCashRegisterSB.csproj b/SWCashRegisterSB/SWCashRegisterSB.csproj new file mode 100644 index 00000000..22d06bb9 --- /dev/null +++ b/SWCashRegisterSB/SWCashRegisterSB.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {5CF33AD0-25E5-4D11-954F-AD914AE820AC} + Exe + SWCashRegisterSB + SWCashRegisterSB + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SWCashRegisterSB/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/SWCashRegisterSB/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000000000000000000000000000000000000..053452f4e0bdc451caa06faac01a3dce08a0c328 GIT binary patch literal 6806 zcmeHMZEqS!5C$7xj2)-Obsfh}QqrbslF}2z?~(k$0n=DbEDMNJ$slLB8(`z(mhSG^ zrj~z8e?irs*v=fUeu-Ntoa7H2Vp#TNo}Jm*<=G(=4uwMh;6tDE+#Nw-zvGq^N>sGD z&y~lVy!LD^%(ST2g}am4PQ>>?DlXj3)T)`JS0bMF9PLTibivb-If?k5S9ZAdD>Mt@ z2;9wba;dUXS*xT{_DYg1u`z;N{|wS=k2^Nu?YJ7GXnc^Y(Ew@YnA~w2o>mWV@B`*J z;soq1rJ!DRn%k!uT$+`d!rp1&R(Lhb9hkG2Yjc}v==7vowOH{SCo5SUPJ}$_G!o7LtRSZrGa1JTPh1_L#1z>FTA5$%Yga^blD!BcaNb zmd)OPC>o}LT)2RW`km2-GIy!zopAXP$S2oVXSixOtVw{E2et!ku{Cf{3Ja7HatmkA zHQIzB*B%0P&T}=dLwm?&O)W2}c~3zODj>l{Raq(OsPq$Rx+goezFUkDW7IH0p;440 z;c(c%H_Fh+pJVx^(oo0n#Pzi_1)TW{xFES@zC~w!OdTBD&;@tIK65lp$jZMdmEmW=^m2NTg4ggkqQM7R}x5LYG4(j+f0f^JSt#LECh5`}EwnhnhtC zRq?$-{#iuU(Wrr2RKk-M6eTo-DyEsLwV*&2^B?-Z=3f^@`BO0iWv_}-A@?jGKgxj; z&T*Fv_sEcGF{=jAugHdJ6b~;>v%~pY(=}q)W0rcvyOzX#LyQ?x(C+m$mLqk=9b*6GXFuMEkAo_^b3?&}I?PTkif&Xc0Q5hvZ^NE(Usy9yB-i zf9?)3eNk6qhl>9JXd=9qFF2SJMl_+yP}0Kbz(VBJKyh_yfL49hAn$qu=AH z*Lh+@QYp7;JVo(7kRv`u9N5SB0Sl2V=0(HAhkcUVKbbHQkgPZ5vc#ic8XNBvtkj-=B1-1`{i2sC|rp|Kgga{(# zDbI}rR(%l-EpxZc&0|El>BeFFj3SsdGfY%n3M3q|%wjfjQcnOG{{_$8)64(> literal 0 HcmV?d00001 diff --git a/SWCashRegisterSB/obj/Debug/SWCashRegisterSB.csprojAssemblyReference.cache b/SWCashRegisterSB/obj/Debug/SWCashRegisterSB.csprojAssemblyReference.cache new file mode 100644 index 0000000000000000000000000000000000000000..542575490bfd452694ad8049c16455ac5bd65e68 GIT binary patch literal 8212 zcmcJT3v3)m8OQI==ewJAUYCTnffSqqeGqflO`N1@LgHQ$k~DGBoXMkcVz2M^?5*#W z-90A`Ep4eNg|?zR3Zfv=N`M4NP>CWQ5+Kn^6bX<36_5a_MFOO@Qj63gwMZ%d|IW>2 z);C5Zkw?03zn%MkznPtxo%!x!@mMVO77DK{ixMy=_q#=}?$^sf?v|!oDdk3Nf7;LG z>z>osd)V=Ow_e*iFqj+2_2>Hgdh^Xn(Da9g}@FRszlkXIN@E_YWWpk^0A28NyKR3e zuqP@Gdo8+Pk~IHQnu5UESGP;M>|#*&(yiy|L3i`@YQy#%FGFs@J?kV<>8B3cm8Rpz zVqLNB?w-sQt$rNvN^Z@rv}0brZPT_Mb|VRsrPEEr=8~+MCyr0qGv-d#Ft~Z!cVhAQ zvM>>N$O33i?doEoRr&y^~bR0eHNEo9qAtCie7 zw{|LQO`x^nLbt}pve1ybAPu$0K9?^{*m`SvYu07rLeJEyD;d<7U8>E|$@Ro5XT@D`-~I zyp84xnk#9pg6XDs?S<8)Z^?3Y!VPjQH;2&UuF+Mkmy-BQC+u3X4fLPaU8*sWq}A3N*G#Od zE0N$Pk%%Xjv@(WPUY*IrGlQ+Fe7#n7C!3zl>|Gr&NL!UVyIc0I?zzEKb<6)7)oMvT zk2~R3++a2y4-ct$>LhxVQMr;O#&9dfVN{9V4KH~PKY=c-m)ua(GyH`xHWtf}n*1tY zm)H3SlPy>l^HwX)?U$=0o+`rjv_^>eg(XU;5e|$h;iJVLLvQ$atc`yO4!fr_xtmMo z6ugvVTEfMRxC2HNiF*{$=kQ@|{PS?;;&?7dTos<`B9kpkAnS;UI*clk`H0T^w1LUf zK{7pf+I0H36@jARDuEB`z)u-~JZU8GG(4*{j`&4li8H7WvoNYi~P2cwE? zK7ktXfCAzwnWuH;jDg8>Rx%%ir_I$vxD^k>s3L)$4m@Q5 z^30aNN8q&w_A|HBVMDwzX1 zv){mE(kGd}g{M99?{F)A52K0%_UXX21|Sni3H$@R_A~zxH{wrk3lNg=i#Yox-k9B;Y9c=2M&wmzI9&9 z@Xq6AZiaU|q>|eepLe%Q;wusU(;uQ0{7oJHh5>%O4d*{g>Q8f(_vG#3lv|s$gdpC6 zQAPIsbshhj0YBQtFGg^5XIVn#(hlaUI`b6+^F*7u9KowvbGWk>I9|hZeFw?fj9YXt zlPlQ5%8nLZ(pz}3vxTK&Xo0^i5KBzV z4>U@d&PDsm+|DR{N=e&&W!7etGVO{|nS&XnOsArKWo~7ZKHVXGWrOaBQQl>CQDKnC&l Date: Mon, 27 Jan 2020 21:27:40 -0500 Subject: [PATCH 2/3] Cash Register Console App by Stephen Bierly --- .gitignore | 4 + .../Calculators/ChangeCalculator.cs | 31 +++++++ .../Interfaces/IChangeCalculator.cs | 14 +++ .../Calculators/RandomChangeCalculator.cs | 40 +++++++++ SWCashRegisterSB/Models/ChangeDenomination.cs | 16 ++++ SWCashRegisterSB/Models/ChangeResult.cs | 20 +++++ .../Models/Interfaces/IChangeResult.cs | 14 +++ .../Models/Interfaces/IDenomination.cs | 15 ++++ SWCashRegisterSB/Program.cs | 81 +++++++++++++++++- SWCashRegisterSB/SWCashRegisterSB.csproj | 9 ++ SWCashRegisterSB/SWCashRegisterSB.sln | 25 ++++++ SWCashRegisterSB/Utils/DenominationUtils.cs | 61 +++++++++++++ SWCashRegisterSB/input.txt | 19 ++++ ...shRegisterSB.csprojAssemblyReference.cache | Bin 8212 -> 424 bytes SWCashRegisterSB/output.txt | 12 +++ 15 files changed, 360 insertions(+), 1 deletion(-) create mode 100644 SWCashRegisterSB/Calculators/ChangeCalculator.cs create mode 100644 SWCashRegisterSB/Calculators/Interfaces/IChangeCalculator.cs create mode 100644 SWCashRegisterSB/Calculators/RandomChangeCalculator.cs create mode 100644 SWCashRegisterSB/Models/ChangeDenomination.cs create mode 100644 SWCashRegisterSB/Models/ChangeResult.cs create mode 100644 SWCashRegisterSB/Models/Interfaces/IChangeResult.cs create mode 100644 SWCashRegisterSB/Models/Interfaces/IDenomination.cs create mode 100644 SWCashRegisterSB/SWCashRegisterSB.sln create mode 100644 SWCashRegisterSB/Utils/DenominationUtils.cs create mode 100644 SWCashRegisterSB/input.txt create mode 100644 SWCashRegisterSB/output.txt diff --git a/.gitignore b/.gitignore index f97f6606..6281743c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,7 @@ ################################################################################ /.vs/CashRegister/v16/Server/sqlite3 +/SWCashRegisterSB/.vs/SWCashRegisterSB/v16 +/SWCashRegisterSB/bin/Debug +/SWCashRegisterSB/obj/Debug +/.vs/slnx.sqlite diff --git a/SWCashRegisterSB/Calculators/ChangeCalculator.cs b/SWCashRegisterSB/Calculators/ChangeCalculator.cs new file mode 100644 index 00000000..53d9a1ea --- /dev/null +++ b/SWCashRegisterSB/Calculators/ChangeCalculator.cs @@ -0,0 +1,31 @@ +using SWCashRegisterSB.Calculators.Interfaces; +using SWCashRegisterSB.Models; +using SWCashRegisterSB.Models.Interfaces; +using SWCashRegisterSB.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Calculators +{ + class ChangeCalculator : IChangeCalculator + { + List IChangeCalculator.CalculateChange(decimal changeAmount) + { + var result = new List(); + + while (changeAmount > 0) + { + var denomination = DenominationUtils.OrderedDenominations.First(x => x.Value <= changeAmount); + var count = decimal.ToInt32(changeAmount / denomination.Value); + + result.Add(new ChangeResult(denomination, count)); + changeAmount -= denomination.Value * count; + } + + return result; + } + } +} diff --git a/SWCashRegisterSB/Calculators/Interfaces/IChangeCalculator.cs b/SWCashRegisterSB/Calculators/Interfaces/IChangeCalculator.cs new file mode 100644 index 00000000..de952367 --- /dev/null +++ b/SWCashRegisterSB/Calculators/Interfaces/IChangeCalculator.cs @@ -0,0 +1,14 @@ +using SWCashRegisterSB.Models.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Calculators.Interfaces +{ + public interface IChangeCalculator + { + List CalculateChange(decimal changeAmount); + } +} diff --git a/SWCashRegisterSB/Calculators/RandomChangeCalculator.cs b/SWCashRegisterSB/Calculators/RandomChangeCalculator.cs new file mode 100644 index 00000000..a51d2f52 --- /dev/null +++ b/SWCashRegisterSB/Calculators/RandomChangeCalculator.cs @@ -0,0 +1,40 @@ +using SWCashRegisterSB.Calculators.Interfaces; +using SWCashRegisterSB.Models; +using SWCashRegisterSB.Models.Interfaces; +using SWCashRegisterSB.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Calculators +{ + public class RandomChangeCalculator : IChangeCalculator + { + + public List CalculateChange(decimal changeAmount) + { + var result = new Dictionary(); + var random = new Random(); + + while(changeAmount > 0) + { + var denominations = DenominationUtils.OrderedDenominations.Where(x => x.Value <= changeAmount).ToList(); + var index = random.Next(0, denominations.Count()); + var denomination = denominations[index]; + var count = random.Next(1, decimal.ToInt32(changeAmount / denomination.Value)); + + if (result.ContainsKey(denomination.Name)) + result[denomination.Name].Quantity += count; + else + result.Add(denomination.Name, new ChangeResult(denomination, count)); + + changeAmount -= denomination.Value * count; + + } + + return result.Values.ToList(); + } + } +} diff --git a/SWCashRegisterSB/Models/ChangeDenomination.cs b/SWCashRegisterSB/Models/ChangeDenomination.cs new file mode 100644 index 00000000..1b1adc0c --- /dev/null +++ b/SWCashRegisterSB/Models/ChangeDenomination.cs @@ -0,0 +1,16 @@ +using SWCashRegisterSB.Models.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Models +{ + public class ChangeDenomination : IDenomination + { + public string Name { get; set; } + public string PluralName { get; set; } + public decimal Value { get; set; } + } +} diff --git a/SWCashRegisterSB/Models/ChangeResult.cs b/SWCashRegisterSB/Models/ChangeResult.cs new file mode 100644 index 00000000..4a7c35ee --- /dev/null +++ b/SWCashRegisterSB/Models/ChangeResult.cs @@ -0,0 +1,20 @@ +using SWCashRegisterSB.Models.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Models +{ + public class ChangeResult : IChangeResult + { + public ChangeResult(IDenomination denomination, int quantity) + { + Denomination = denomination; + Quantity = quantity; + } + public IDenomination Denomination { get; set; } + public int Quantity { get; set; } + } +} diff --git a/SWCashRegisterSB/Models/Interfaces/IChangeResult.cs b/SWCashRegisterSB/Models/Interfaces/IChangeResult.cs new file mode 100644 index 00000000..3f5a06fa --- /dev/null +++ b/SWCashRegisterSB/Models/Interfaces/IChangeResult.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Models.Interfaces +{ + public interface IChangeResult + { + IDenomination Denomination { get; set; } + int Quantity { get; set; } + } +} diff --git a/SWCashRegisterSB/Models/Interfaces/IDenomination.cs b/SWCashRegisterSB/Models/Interfaces/IDenomination.cs new file mode 100644 index 00000000..7c36c7ec --- /dev/null +++ b/SWCashRegisterSB/Models/Interfaces/IDenomination.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Models.Interfaces +{ + public interface IDenomination + { + string Name { get; set; } + string PluralName { get; set; } + decimal Value { get; set; } + } +} diff --git a/SWCashRegisterSB/Program.cs b/SWCashRegisterSB/Program.cs index 0f897fd1..4c10838b 100644 --- a/SWCashRegisterSB/Program.cs +++ b/SWCashRegisterSB/Program.cs @@ -1,15 +1,94 @@ -using System; +using SWCashRegisterSB.Utils; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SWCashRegisterSB { + /// + /// Softwriters Cash Register by Stephen Bierly + /// Input file location is: "{RepoPath}\\SWCashRegisterSB\\input.txt" + /// Output file location is: "{RepoPath}\\SWCashRegisterSB\\output.txt" + /// class Program { static void Main(string[] args) { + var basePath = Path.GetFullPath(@"..\..\"); + var inputPath = basePath + "input.txt"; + var outputPath = basePath + "output.txt"; + + + if (!File.Exists(inputPath)) + { + Console.WriteLine($"Could not find input file. Expected to be '{inputPath}'"); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + return; + } + + try + { + using (StreamWriter outWriter = new StreamWriter(outputPath, false)) + { + var currentLineNum = 1; + foreach (var line in File.ReadLines(inputPath)) + { + var parts = line.Split(','); + decimal amountDue; + decimal amountPaid; + if(parts.Length != 2 || !decimal.TryParse(parts[0], out amountDue) || !decimal.TryParse(parts[1], out amountPaid)) + { + Console.WriteLine($"Improperly formated line '{line}' on line '{currentLineNum}"); + currentLineNum++; + continue; + } + + //Excluding the possibility of refunds currently + if(amountDue < 0 || amountPaid < 0) + { + Console.WriteLine($"Amount Paid ('{amountPaid}') and Amount Due ('{amountDue}') must be positive."); + continue; + } + + var changeDue = amountPaid - amountDue; + + if(changeDue < 0) + { + Console.WriteLine($"Insufficient payment on line '{currentLineNum}', payment is '{Math.Abs(changeDue)}' less than required."); + currentLineNum++; + continue; + } + + if (changeDue == 0) + { + Console.WriteLine($"No change due on line {currentLineNum}"); + currentLineNum++; + continue; + } + + var calculator = DenominationUtils.GetChangeCalculator(amountDue); + + var change = calculator.CalculateChange(changeDue); + + var changeOutputLine = DenominationUtils.GetChangeOutput(change); + + outWriter.WriteLine(changeOutputLine); + currentLineNum++; + } + + } + } + catch(Exception e) + { + Console.WriteLine($"Unexpected Error : '{e.Message}'"); + } + + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); } } } diff --git a/SWCashRegisterSB/SWCashRegisterSB.csproj b/SWCashRegisterSB/SWCashRegisterSB.csproj index 22d06bb9..80280149 100644 --- a/SWCashRegisterSB/SWCashRegisterSB.csproj +++ b/SWCashRegisterSB/SWCashRegisterSB.csproj @@ -43,11 +43,20 @@ + + + + + + + + + \ No newline at end of file diff --git a/SWCashRegisterSB/SWCashRegisterSB.sln b/SWCashRegisterSB/SWCashRegisterSB.sln new file mode 100644 index 00000000..4180722a --- /dev/null +++ b/SWCashRegisterSB/SWCashRegisterSB.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SWCashRegisterSB", "SWCashRegisterSB.csproj", "{5CF33AD0-25E5-4D11-954F-AD914AE820AC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5CF33AD0-25E5-4D11-954F-AD914AE820AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CF33AD0-25E5-4D11-954F-AD914AE820AC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CF33AD0-25E5-4D11-954F-AD914AE820AC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CF33AD0-25E5-4D11-954F-AD914AE820AC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {069B2EC7-CEE6-4846-94FE-69BF508FB37C} + EndGlobalSection +EndGlobal diff --git a/SWCashRegisterSB/Utils/DenominationUtils.cs b/SWCashRegisterSB/Utils/DenominationUtils.cs new file mode 100644 index 00000000..c5dfbfc7 --- /dev/null +++ b/SWCashRegisterSB/Utils/DenominationUtils.cs @@ -0,0 +1,61 @@ +using SWCashRegisterSB.Calculators; +using SWCashRegisterSB.Calculators.Interfaces; +using SWCashRegisterSB.Models; +using SWCashRegisterSB.Models.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SWCashRegisterSB.Utils +{ + public static class DenominationUtils + { + #region static Change Denominations... + public readonly static ChangeDenomination Hundred = new ChangeDenomination { Name = "hundred", PluralName = "hundreds", Value = 100 }; + public readonly static ChangeDenomination Fifty = new ChangeDenomination { Name = "fifty", PluralName = "fifties", Value = 50 }; + public readonly static ChangeDenomination Twenty = new ChangeDenomination { Name = "twenty", PluralName = "twenties", Value = 20 }; + public readonly static ChangeDenomination Ten = new ChangeDenomination { Name = "ten", PluralName = "tens", Value = 10 }; + public readonly static ChangeDenomination Five = new ChangeDenomination { Name = "five", PluralName = "fives", Value = 5 }; + public readonly static ChangeDenomination Dollar = new ChangeDenomination { Name = "dollar", PluralName = "dollars", Value = 1 }; + + public readonly static ChangeDenomination Quarter = new ChangeDenomination { Name = "quarter", PluralName = "quarters", Value = 0.25M }; + public readonly static ChangeDenomination Dime = new ChangeDenomination { Name = "dime", PluralName = "dimes", Value = 0.10M }; + public readonly static ChangeDenomination Nickel = new ChangeDenomination { Name = "nickel", PluralName = "nickels", Value = 0.05M }; + public readonly static ChangeDenomination Penny = new ChangeDenomination { Name = "penny", PluralName = "pennies", Value = 0.01M }; + + public readonly static List OrderedDenominations = new List { Hundred, Fifty, Twenty, Ten, Five, Dollar, Quarter, Dime, Nickel, Penny }; + #endregion + + private readonly static RandomChangeCalculator _randomChangeCalculator = new RandomChangeCalculator(); + private readonly static ChangeCalculator _changeCalculator = new ChangeCalculator(); + + public static IChangeCalculator GetChangeCalculator(decimal amountDue) + { + if (amountDue % 0.03m == 0) + return _randomChangeCalculator; + else + return _changeCalculator; + } + + public static string GetChangeOutput(List changeResults) + { + var changeSB = new StringBuilder(); + + var sortedResults = changeResults.OrderByDescending(x => x.Denomination.Value); + + foreach(var result in sortedResults) + { + if (changeSB.Length > 0) + changeSB.Append(','); + + var plural = result.Quantity > 1; + + changeSB.Append($"{result.Quantity} {(plural ? result.Denomination.PluralName : result.Denomination.Name)}"); + } + + return changeSB.ToString(); + } + } +} diff --git a/SWCashRegisterSB/input.txt b/SWCashRegisterSB/input.txt new file mode 100644 index 00000000..43c5d189 --- /dev/null +++ b/SWCashRegisterSB/input.txt @@ -0,0 +1,19 @@ +2.12,3.00 +1.75,2.00 +1.97,2.00 +3.33,5.00 +2.99,3 +3.95,5.00 +NaN,NaN +5,000.00,6,000.00 +5.06,50.00 +5.04,20.00 +2.21,10.00 +6.11,5.10 +891.31,1000.00 +32.21,100.00 +6.31,6.31 +3.33,3.33 +-3.21,4.33 +1.05,-2.22 +10.01,50 diff --git a/SWCashRegisterSB/obj/Debug/SWCashRegisterSB.csprojAssemblyReference.cache b/SWCashRegisterSB/obj/Debug/SWCashRegisterSB.csprojAssemblyReference.cache index 542575490bfd452694ad8049c16455ac5bd65e68..24df8ab71c7fe300bafe3814e087f18338735c85 100644 GIT binary patch delta 28 ecmbQ@u!4DmKO>{aCWQ5+Kn^6bX<36_5a_MFOO@Qj63gwMZ%d|IW>2 z);C5Zkw?03zn%MkznPtxo%!x!@mMVO77DK{ixMy=_q#=}?$^sf?v|!oDdk3Nf7;LG z>z>osd)V=Ow_e*iFqj+2_2>Hgdh^Xn(Da9g}@FRszlkXIN@E_YWWpk^0A28NyKR3e zuqP@Gdo8+Pk~IHQnu5UESGP;M>|#*&(yiy|L3i`@YQy#%FGFs@J?kV<>8B3cm8Rpz zVqLNB?w-sQt$rNvN^Z@rv}0brZPT_Mb|VRsrPEEr=8~+MCyr0qGv-d#Ft~Z!cVhAQ zvM>>N$O33i?doEoRr&y^~bR0eHNEo9qAtCie7 zw{|LQO`x^nLbt}pve1ybAPu$0K9?^{*m`SvYu07rLeJEyD;d<7U8>E|$@Ro5XT@D`-~I zyp84xnk#9pg6XDs?S<8)Z^?3Y!VPjQH;2&UuF+Mkmy-BQC+u3X4fLPaU8*sWq}A3N*G#Od zE0N$Pk%%Xjv@(WPUY*IrGlQ+Fe7#n7C!3zl>|Gr&NL!UVyIc0I?zzEKb<6)7)oMvT zk2~R3++a2y4-ct$>LhxVQMr;O#&9dfVN{9V4KH~PKY=c-m)ua(GyH`xHWtf}n*1tY zm)H3SlPy>l^HwX)?U$=0o+`rjv_^>eg(XU;5e|$h;iJVLLvQ$atc`yO4!fr_xtmMo z6ugvVTEfMRxC2HNiF*{$=kQ@|{PS?;;&?7dTos<`B9kpkAnS;UI*clk`H0T^w1LUf zK{7pf+I0H36@jARDuEB`z)u-~JZU8GG(4*{j`&4li8H7WvoNYi~P2cwE? zK7ktXfCAzwnWuH;jDg8>Rx%%ir_I$vxD^k>s3L)$4m@Q5 z^30aNN8q&w_A|HBVMDwzX1 zv){mE(kGd}g{M99?{F)A52K0%_UXX21|Sni3H$@R_A~zxH{wrk3lNg=i#Yox-k9B;Y9c=2M&wmzI9&9 z@Xq6AZiaU|q>|eepLe%Q;wusU(;uQ0{7oJHh5>%O4d*{g>Q8f(_vG#3lv|s$gdpC6 zQAPIsbshhj0YBQtFGg^5XIVn#(hlaUI`b6+^F*7u9KowvbGWk>I9|hZeFw?fj9YXt zlPlQ5%8nLZ(pz}3vxTK&Xo0^i5KBzV z4>U@d&PDsm+|DR{N=e&&W!7etGVO{|nS&XnOsArKWo~7ZKHVXGWrOaBQQl>CQDKnC&l Date: Mon, 27 Jan 2020 21:30:52 -0500 Subject: [PATCH 3/3] A minor code consistency update to a file I missed --- SWCashRegisterSB/Calculators/ChangeCalculator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SWCashRegisterSB/Calculators/ChangeCalculator.cs b/SWCashRegisterSB/Calculators/ChangeCalculator.cs index 53d9a1ea..bd62bd82 100644 --- a/SWCashRegisterSB/Calculators/ChangeCalculator.cs +++ b/SWCashRegisterSB/Calculators/ChangeCalculator.cs @@ -10,9 +10,9 @@ namespace SWCashRegisterSB.Calculators { - class ChangeCalculator : IChangeCalculator + public class ChangeCalculator : IChangeCalculator { - List IChangeCalculator.CalculateChange(decimal changeAmount) + public List CalculateChange(decimal changeAmount) { var result = new List();