From 3f41f9998b804a1dec9c071b1b14af12314bae03 Mon Sep 17 00:00:00 2001 From: ismoil8282 <137428819+ismoil8282@users.noreply.github.com> Date: Tue, 26 Sep 2023 15:53:17 +0300 Subject: [PATCH 1/2] Ismoil - Homework05 --- Homework05/Homework05.sln | 25 ++++++++ .../CannotEnterAnotherSymbolException.cs | 17 ++++++ .../Homework05/CannotEnterFiveException.cs | 16 +++++ Homework05/Homework05/Homework05.csproj | 10 ++++ .../Homework05/IncorrectIputException.cs | 13 ++++ Homework05/Homework05/Program.cs | 60 +++++++++++++++++++ Homework05/Homework05/errors.txt | 1 + 7 files changed, 142 insertions(+) create mode 100644 Homework05/Homework05.sln create mode 100644 Homework05/Homework05/CannotEnterAnotherSymbolException.cs create mode 100644 Homework05/Homework05/CannotEnterFiveException.cs create mode 100644 Homework05/Homework05/Homework05.csproj create mode 100644 Homework05/Homework05/IncorrectIputException.cs create mode 100644 Homework05/Homework05/Program.cs create mode 100644 Homework05/Homework05/errors.txt diff --git a/Homework05/Homework05.sln b/Homework05/Homework05.sln new file mode 100644 index 0000000..01df8ad --- /dev/null +++ b/Homework05/Homework05.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Homework05", "Homework05\Homework05.csproj", "{4CB9E2B0-4B50-4947-85FC-2E00393DA325}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B7C80557-3166-4939-A5C0-521CB9130E95} + EndGlobalSection +EndGlobal diff --git a/Homework05/Homework05/CannotEnterAnotherSymbolException.cs b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs new file mode 100644 index 0000000..a9488ce --- /dev/null +++ b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Homework05 +{ + internal class CannotEnterAnotherSymbolException : Exception + { + public CannotEnterAnotherSymbolException(string message) + : base (message) + { + + } + } +} diff --git a/Homework05/Homework05/CannotEnterFiveException.cs b/Homework05/Homework05/CannotEnterFiveException.cs new file mode 100644 index 0000000..0dc36fe --- /dev/null +++ b/Homework05/Homework05/CannotEnterFiveException.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Homework05 +{ + internal class CannotEnterFiveException : IncorrectIputException + { + public CannotEnterFiveException(string message) + : base(message) + { } + + } +} diff --git a/Homework05/Homework05/Homework05.csproj b/Homework05/Homework05/Homework05.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Homework05/Homework05/Homework05.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Homework05/Homework05/IncorrectIputException.cs b/Homework05/Homework05/IncorrectIputException.cs new file mode 100644 index 0000000..effb5e7 --- /dev/null +++ b/Homework05/Homework05/IncorrectIputException.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Homework05 +{ + internal class IncorrectIputException :ArgumentException + { + public IncorrectIputException(string message) { } + } +} diff --git a/Homework05/Homework05/Program.cs b/Homework05/Homework05/Program.cs new file mode 100644 index 0000000..ea924f9 --- /dev/null +++ b/Homework05/Homework05/Program.cs @@ -0,0 +1,60 @@ +namespace Homework05 +{ + internal class Program + { + static void Main(string[] args) + { + try + { + Console.WriteLine("Shell we start calculating!"); + Console.Write("Enter first number : "); + int firstNumber = int.Parse(Console.ReadLine()); + Console.Write("Enter action :"); + char action = Console.ReadLine()[0]; + Console.Write("Enter second number : "); + int secondNumber = int.Parse(Console.ReadLine()); + + Calculate(firstNumber, secondNumber, action); + + } + catch (CannotEnterAnotherSymbolException ex) + { + Console.WriteLine("Wrong symbol . Please, try again"); + } + catch (Exception ex) + { + Console.WriteLine("Something went wrong!"); + } + Thread.Sleep(3000); + Console.Clear(); + Main(args); + } + + public static void Calculate(int firstNum, int secondNum, char action) + { + int result; + + switch (action) + { + case '+': + result = firstNum + secondNum; + break; + case '-': + result = firstNum - secondNum; + break; + case '*': + result = firstNum * secondNum; + break; + case '/': + result = firstNum / secondNum; + break; + default: throw new CannotEnterAnotherSymbolException("Wrong symbol!"); + } + + Console.Clear(); + Console.WriteLine($"{firstNum} {action} {secondNum} = {result}"); + + } + + } +} \ No newline at end of file diff --git a/Homework05/Homework05/errors.txt b/Homework05/Homework05/errors.txt new file mode 100644 index 0000000..cd876a9 --- /dev/null +++ b/Homework05/Homework05/errors.txt @@ -0,0 +1 @@ +Value does not fall within the expected range. \ No newline at end of file From 13770a7c62d3014c709be30977d4c0e56087ef8b Mon Sep 17 00:00:00 2001 From: ismoil8282 <137428819+ismoil8282@users.noreply.github.com> Date: Tue, 26 Sep 2023 16:16:15 +0300 Subject: [PATCH 2/2] ismoil HomeWork05 --- .../CannotEnterAnotherSymbolException.cs | 4 ++-- .../Homework05/CannotEnterFiveException.cs | 16 ---------------- Homework05/Homework05/IncorrectIputException.cs | 13 ------------- Homework05/Homework05/Program.cs | 1 - 4 files changed, 2 insertions(+), 32 deletions(-) delete mode 100644 Homework05/Homework05/CannotEnterFiveException.cs delete mode 100644 Homework05/Homework05/IncorrectIputException.cs diff --git a/Homework05/Homework05/CannotEnterAnotherSymbolException.cs b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs index a9488ce..6d7c0d0 100644 --- a/Homework05/Homework05/CannotEnterAnotherSymbolException.cs +++ b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs @@ -8,8 +8,8 @@ namespace Homework05 { internal class CannotEnterAnotherSymbolException : Exception { - public CannotEnterAnotherSymbolException(string message) - : base (message) + public CannotEnterAnotherSymbolException(string str) + : base (str) { } diff --git a/Homework05/Homework05/CannotEnterFiveException.cs b/Homework05/Homework05/CannotEnterFiveException.cs deleted file mode 100644 index 0dc36fe..0000000 --- a/Homework05/Homework05/CannotEnterFiveException.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Homework05 -{ - internal class CannotEnterFiveException : IncorrectIputException - { - public CannotEnterFiveException(string message) - : base(message) - { } - - } -} diff --git a/Homework05/Homework05/IncorrectIputException.cs b/Homework05/Homework05/IncorrectIputException.cs deleted file mode 100644 index effb5e7..0000000 --- a/Homework05/Homework05/IncorrectIputException.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Homework05 -{ - internal class IncorrectIputException :ArgumentException - { - public IncorrectIputException(string message) { } - } -} diff --git a/Homework05/Homework05/Program.cs b/Homework05/Homework05/Program.cs index ea924f9..af116e2 100644 --- a/Homework05/Homework05/Program.cs +++ b/Homework05/Homework05/Program.cs @@ -50,7 +50,6 @@ public static void Calculate(int firstNum, int secondNum, char action) break; default: throw new CannotEnterAnotherSymbolException("Wrong symbol!"); } - Console.Clear(); Console.WriteLine($"{firstNum} {action} {secondNum} = {result}");