Skip to content

Code Submission - #46

Closed
cparkes1 wants to merge 7 commits into
the-csharp-academy:mainfrom
cparkes1:main
Closed

cparkes1 wants to merge 7 commits into
the-csharp-academy:mainfrom
cparkes1:main

Conversation

@cparkes1

Copy link
Copy Markdown

No description provided.

Widened num1 and num2 from int to double and replaced Convert.ToInt32(...) with Convert.ToDouble(...). Updates Console.ReadLine() parsing to accept decimal input and preserve fractional results instead of truncating to integers.
Refactor a one-shot console calculator into a structured, user-friendly app. Add Calculator.DoOperation(double,double,string) implementing +, -, *, / (returns NaN for invalid math like divide-by-zero) and include System.Text.RegularExpressions for operator validation. Replace procedural inline reads with a Program.Main repeat loop (endApp) and remove legacy globals, single-run menu/switch, and ReadKey flow. Improve input handling (double.TryParse loops, Regex for operators), add try/catch around operations, clearer user messages, and format numeric output with "{0:0.##}".
Refactor arithmetic logic out of the console Program into a new CalculatorLibrary project. Added CalculatorLibrary.cs with Calculator.DoOperation(double, double, string) moved from Program.cs. Updated CalculatorLibrary.csproj to target net10.0 and enable implicit usings and nullable reference types. Removed DoOperation implementation from Program.cs and added "using CalculatorLibrary;" to consume the library. Added a ProjectReference in calculator.cparkes1.csproj and updated calculator.cparkes1.slnx to include the new project so the logic is reusable and both projects target net10.0.
Add System.Diagnostics-based logging and convert Calculator.DoOperation from a static to an instance method. Introduce a public Calculator() constructor that creates a StreamWriter-backed TextWriterTraceListener ("calculator.log"), adds it to Trace.Listeners, enables Trace.AutoFlush, and writes startup trace lines. Update DoOperation signature to public double DoOperation(...) and add Trace.WriteLine calls to log each arithmetic operation and result (add, subtract, multiply, divide). Update Program.cs to instantiate Calculator and call calculator.DoOperation(...) instead of the static call. Behavior change: logging to calculator.log is enabled and callers must now create a Calculator instance instead of calling the method statically.
Replaced plain-text Trace logging with structured JSON output using Newtonsoft.Json. CalculatorLibrary now creates calculatorlog.json, initializes a JsonTextWriter (indented) and a root object with an "Operations" array, and writes a JSON object per operation with properties: Operand1, Operand2, Operation (Add/Subtract/Multiply/Divide) and Result. Removed Trace.WriteLine calls and Trace listener setup; added a JsonWriter field and writer.WriteStartObject/EndObject calls. Added public Finish() to close the array/object and the writer, and updated Program.cs to call calculator.Finish() before exit. Added PackageReference to Newtonsoft.Json v13.0.4 and the corresponding using directive.
@github-actions

Copy link
Copy Markdown

🚀 Project Submitted!

Thanks for submitting your project! I will review it soon.

📋 Please check the dashboard to make sure the project is marked as Pending.

⚠️ If it's not marked as pending, submit it manually using the URL for this PR.

@TheCSharpAcademy

Copy link
Copy Markdown

@cparkes1 Project approved! 😄✅ It's a shame you didn't complete the challenges this time. 😟 It's always a good use of your time. But nothing stops you from revisiting the project later. Keep in mind that it's a very competitive environment out there in the software development industry. I highly recommend you do everything in your power to stand out from the competition. 👩‍🎤

Feedback
🔍️ It's a pretty straight-forward project, so we don't have much to add, as you followed the tutorial correctly I hope it gave you a good understanding of a few concepts such as error handling, interacting with the file system, debugging and handling multiple projects under one solution.

I noticed that you haven't completed any of our courses yet. I suggest you try our Intro to Object Oriented Programming course next. This will close gaps in your knowledge and give you more confidence about OOP

👪Oh and if possible join our Discord Community and add your username to your profile so you can be part of the community as well. 😁

☕If you like our roadmap, please consider buying us a coffee. We appreciate your help 🙂

Overall good work!✋🏻Looking forward to seeing your next projects!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants