From d401d40337a7cbaaef2693a407feff3134994f32 Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Wed, 26 Aug 2020 09:48:26 +0200 Subject: [PATCH 1/6] Bara skrift --- Session02/Session02.sln | 25 +++++++++++++++++++ Session02/Session02Exercise01/Program.cs | 12 +++++++++ .../Session02Exercise01.csproj | 8 ++++++ 3 files changed, 45 insertions(+) create mode 100644 Session02/Session02.sln create mode 100644 Session02/Session02Exercise01/Program.cs create mode 100644 Session02/Session02Exercise01/Session02Exercise01.csproj diff --git a/Session02/Session02.sln b/Session02/Session02.sln new file mode 100644 index 0000000..30b44a7 --- /dev/null +++ b/Session02/Session02.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B8AA34BE-8E82-4BCB-85BD-2689F1C50616} + EndGlobalSection +EndGlobal diff --git a/Session02/Session02Exercise01/Program.cs b/Session02/Session02Exercise01/Program.cs new file mode 100644 index 0000000..a37fc8d --- /dev/null +++ b/Session02/Session02Exercise01/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Session02Exercise01 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/Session02/Session02Exercise01/Session02Exercise01.csproj b/Session02/Session02Exercise01/Session02Exercise01.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Exercise01/Session02Exercise01.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + From 07112046462cd87c77773a89d29822d22304ccd5 Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Wed, 26 Aug 2020 10:26:36 +0200 Subject: [PATCH 2/6] =?UTF-8?q?=C3=84ndrat?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Session02/Session02Exercise01/Program.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Session02/Session02Exercise01/Program.cs b/Session02/Session02Exercise01/Program.cs index a37fc8d..7fa8512 100644 --- a/Session02/Session02Exercise01/Program.cs +++ b/Session02/Session02Exercise01/Program.cs @@ -6,7 +6,9 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + Console.WriteLine("Hello world!"); + var integer = 0; + Console.WriteLine("integer is" + integer.ToString()); } } } From 9bba491b6b18283ad1952a23ab88c3739f95d955 Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Wed, 26 Aug 2020 10:40:11 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Inneh=C3=A5ller=20str=C3=A4ng?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Session02/Session02Exercise01/Program.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Session02/Session02Exercise01/Program.cs b/Session02/Session02Exercise01/Program.cs index a37fc8d..9c56cdc 100644 --- a/Session02/Session02Exercise01/Program.cs +++ b/Session02/Session02Exercise01/Program.cs @@ -7,6 +7,10 @@ class Program static void Main(string[] args) { Console.WriteLine("Hello World!"); + + string stringValue = "My string is cool!"; + + Console.WriteLine($"The string value of stringValie is {stringValue}"); } } } From 6778b99b440daeadd31ec2f24b98a3892354aa34 Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Fri, 28 Aug 2020 09:21:55 +0200 Subject: [PATCH 4/6] Did someting! --- Session02/Excample02/Program.cs | 31 +++++++ .../Excample02/Session02exercise02.csproj | 8 ++ Session02/Session02.sln | 18 +++++ Session02/Session02Excersise03/Program.cs | 81 +++++++++++++++++++ .../Session02Excersise03.csproj | 8 ++ Session02/Session02Excersise04/Program.cs | 40 +++++++++ .../Session02Excersise04.csproj | 8 ++ 7 files changed, 194 insertions(+) create mode 100644 Session02/Excample02/Program.cs create mode 100644 Session02/Excample02/Session02exercise02.csproj create mode 100644 Session02/Session02Excersise03/Program.cs create mode 100644 Session02/Session02Excersise03/Session02Excersise03.csproj create mode 100644 Session02/Session02Excersise04/Program.cs create mode 100644 Session02/Session02Excersise04/Session02Excersise04.csproj diff --git a/Session02/Excample02/Program.cs b/Session02/Excample02/Program.cs new file mode 100644 index 0000000..ebb556a --- /dev/null +++ b/Session02/Excample02/Program.cs @@ -0,0 +1,31 @@ +using System; +using System.Runtime.CompilerServices; + +namespace Excample02 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Do you want to enter your name? (y/n)"); + var key = Console.ReadKey(); + + if (key.KeyChar == 'n') + return; + + else if (key.KeyChar == 'y') + { + Console.WriteLine("\nEnter your name: "); + var name = Console.ReadLine(); + + Console.WriteLine($"Hello, {name}"); + } + else + { + Console.WriteLine("\nI don't understand?"); + } + Console.WriteLine("Press any key to exit program..."); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Excample02/Session02exercise02.csproj b/Session02/Excample02/Session02exercise02.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Excample02/Session02exercise02.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02.sln b/Session02/Session02.sln index 30b44a7..d0032a3 100644 --- a/Session02/Session02.sln +++ b/Session02/Session02.sln @@ -5,6 +5,12 @@ VisualStudioVersion = 16.0.30413.136 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{5781BFBB-1E01-47F7-A1DE-5BD53D78E140}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02exercise02", "Excample02\Session02exercise02.csproj", "{6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise03", "Session02Excersise03\Session02Excersise03.csproj", "{4309C8FA-CF78-44EB-9535-36703D508250}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Excersise04", "Session02Excersise04\Session02Excersise04.csproj", "{85B305B6-E306-4951-ADE5-01656F70DA96}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +21,18 @@ Global {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Debug|Any CPU.Build.0 = Debug|Any CPU {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.ActiveCfg = Release|Any CPU {5781BFBB-1E01-47F7-A1DE-5BD53D78E140}.Release|Any CPU.Build.0 = Release|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B5DA0D0-23A1-47A2-B34F-A0A125A584FD}.Release|Any CPU.Build.0 = Release|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4309C8FA-CF78-44EB-9535-36703D508250}.Release|Any CPU.Build.0 = Release|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85B305B6-E306-4951-ADE5-01656F70DA96}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Session02/Session02Excersise03/Program.cs b/Session02/Session02Excersise03/Program.cs new file mode 100644 index 0000000..0c9fdf2 --- /dev/null +++ b/Session02/Session02Excersise03/Program.cs @@ -0,0 +1,81 @@ +using System; +using System.Net.WebSockets; + +namespace Session02Excersise03 +{ + class Program + { + static void Main(string[] args) + { + //Binary operation + var additionResult = 1 + 2; + Console.WriteLine($"Addition result {additionResult}"); + + var incrementResult = ++additionResult; + Console.WriteLine($"Increment result {incrementResult}"); + + var trueValue = true; + + var falseValue = false; + + // Bitwise operationer + var andResult = 0b0010 & 0b0100; //0b0110; + var orResult = 0b0001 | 0b0001; //0b0001; + var xorResult = 0b0001 ^ 0b0001; //0b0000; + + Console.WriteLine($"and result {andResult}"); + Console.WriteLine($"or result {orResult}"); + Console.WriteLine($"xor result {xorResult}"); + + var modulResult = 3 % 2; + Console.WriteLine($"modul result {modulResult}"); + + var highInteger = 1000; + var integerDivisionResult = highInteger / 3; + var doubleDivissionResult = highInteger / 3.0; + + Console.WriteLine($"integer division result {integerDivisionResult}"); + Console.WriteLine($"double division result {doubleDivissionResult}"); + + //implicit värdekonvertering till double + var forcedIntDivisionResult = (int)(highInteger / 3.0); + Console.WriteLine($"forced int division result {forcedIntDivisionResult}"); + + var conversionResult = Convert.ToInt32(doubleDivissionResult); + + Console.WriteLine($"Conversion result {conversionResult}"); + + var midpointDivisionResult = 10.0 / 3.0; + + Console.WriteLine($"Midpoint division result {midpointDivisionResult}"); + Console.WriteLine($"castToInt" + ((int)midpointDivisionResult).ToString()); + Console.WriteLine($"ceiling " + Math.Ceiling(midpointDivisionResult)); + Console.WriteLine($"floor " + Math.Floor(midpointDivisionResult)); + Console.WriteLine($"ceiling " + Math.Round(midpointDivisionResult)); + + //T + additionResult += 2; //Samma som (additionalResult = additionalResult + 2) + additionResult -= 2; + additionResult *= 2; + additionResult /= 2; + + //Boelska jämförelseoperatorer + var greaterThanResult = 5 > 3; + var lessThanResult = 5 < 3; + var greaterOrEqual = 5 >= 5; + var lessOrEqual = 3 <= 5; + + Console.WriteLine($"greaterThanResult {greaterThanResult}"); + Console.WriteLine($"lessThanResult {lessThanResult}"); + Console.WriteLine($"greater or Equal {greaterOrEqual}"); + Console.WriteLine($"less or equal {lessOrEqual}"); + + var andOperationsResult = true && false; + var orOperationResult = false || true; + + Console.WriteLine($"And operations Result {andOperationsResult}"); + Console.WriteLine($"Or operations Result {orOperationResult}"); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Session02Excersise03/Session02Excersise03.csproj b/Session02/Session02Excersise03/Session02Excersise03.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Excersise03/Session02Excersise03.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02Excersise04/Program.cs b/Session02/Session02Excersise04/Program.cs new file mode 100644 index 0000000..194b989 --- /dev/null +++ b/Session02/Session02Excersise04/Program.cs @@ -0,0 +1,40 @@ +using System; + +namespace Session02Excersise04 +{ + class Program + { + static void Main(string[] args) + { + //Console.WriteLine("Ange ålder: "); + + //var input = Console.ReadLine(); + //var integer = Convert.ToInt32(input); + + //if (integer >= 18) + //{ + // Console.WriteLine("Du får köpa tobaksprodukter."); + //} + //else + //{ + // Console.WriteLine("Du får inte köpa tobak! "); + //} + + //if (integer >= 40) + //{ + // Console.WriteLine("Men du är för gammal för att röka!"); + //} + + Console.WriteLine("Ange en badtemperatur i grader C: "); + + var input = Console.ReadLine(); + var integer = Convert.ToInt32(input); + + string waterLabel = integer >= 27 ? "Det går bra att bada" : "Det går inte att bada"; + Console.WriteLine($"{waterLabel} i havet!"); + + Console.WriteLine("Tryck på valfri tangent för att avsluta..."); + Console.ReadKey(true); + } + } +} diff --git a/Session02/Session02Excersise04/Session02Excersise04.csproj b/Session02/Session02Excersise04/Session02Excersise04.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02Excersise04/Session02Excersise04.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + From 2d3de8e08f40e70b13663b4cde71317b030b21f1 Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Fri, 28 Aug 2020 13:13:02 +0200 Subject: [PATCH 5/6] Progress ongoing. --- Session03/Session03.sln | 25 ++++++ Session03/Session03Exersise01/Program.cs | 82 +++++++++++++++++++ .../Session03Exersise01.csproj | 8 ++ 3 files changed, 115 insertions(+) create mode 100644 Session03/Session03.sln create mode 100644 Session03/Session03Exersise01/Program.cs create mode 100644 Session03/Session03Exersise01/Session03Exersise01.csproj diff --git a/Session03/Session03.sln b/Session03/Session03.sln new file mode 100644 index 0000000..240772e --- /dev/null +++ b/Session03/Session03.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exersise01", "Session03Exersise01\Session03Exersise01.csproj", "{9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9C90BA88-D314-4C64-8D2C-BDE6CA882C1E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DAB41CAE-214D-40AB-BD39-8D5A82665136} + EndGlobalSection +EndGlobal diff --git a/Session03/Session03Exersise01/Program.cs b/Session03/Session03Exersise01/Program.cs new file mode 100644 index 0000000..d314295 --- /dev/null +++ b/Session03/Session03Exersise01/Program.cs @@ -0,0 +1,82 @@ +using System; +using System.Globalization; +using System.Linq; + +namespace Session03Exersise01 +{ + class Program + { + static void Main(string[] args) + { + double doubleMid = 0; + double dblSum = 0; + + Console.WriteLine("Ange ett antal siffror, separerat med kommatecken"); + var input = Console.ReadLine(); + var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries); + double?[] numberArray = new double?[inputArray.Length]; + + for (int i = 0; i < inputArray.Length; i++) + { + bool parsed; + + try + { + numberArray[i] = Convert.ToDouble(inputArray[i]); + parsed = true; + } + + catch (Exception) + { + numberArray[i] = 0; + parsed = false; + } + + if (parsed == false) + { + continue; + } + + dblSum += numberArray[i].Value; + } + doubleMid = dblSum / numberArray.Length; + + + Console.WriteLine($"Min value is: {numberArray.Min()} Maxvalue is: {numberArray.Max()} Total value is: {dblSum} Midvalue is: {doubleMid}"); + + //for (int i = 0; i < inputArray.Length; i++) + //{ + // NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; + // bool parsed = double.TryParse(inputArray[i], out double parsedValue); + + //if (parsed == true) + //{ + // numberArray[i] = parsedValue; + //} + //else + //{ + // numberArray[i] = null; + //} + } + + //static double GetDoubleValue(string input) + //{ + // try + // { + // //numberArray[i] = Convert.ToDouble(inputArray[i]); + // var result = int.Parse(input); + // return result; + // } + // catch (FormatException ex) + // { + // return double.MinValue; + + // throw ex; + // } + // catch (Exception ex) + // { + // return 0; + // } + //} + } +} diff --git a/Session03/Session03Exersise01/Session03Exersise01.csproj b/Session03/Session03Exersise01/Session03Exersise01.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session03/Session03Exersise01/Session03Exersise01.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + From ca3005fb6156deb11d1799ba05c43aa05ea1af7c Mon Sep 17 00:00:00 2001 From: "PROGRAMMERINGEN\\Patrik" Date: Sun, 30 Aug 2020 16:29:12 +0200 Subject: [PATCH 6/6] Added an integer to get correct math in the division for midle value. --- Session03/Session03Exersise01/Program.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Session03/Session03Exersise01/Program.cs b/Session03/Session03Exersise01/Program.cs index d314295..75efa1f 100644 --- a/Session03/Session03Exersise01/Program.cs +++ b/Session03/Session03Exersise01/Program.cs @@ -10,6 +10,7 @@ static void Main(string[] args) { double doubleMid = 0; double dblSum = 0; + int intParsedOk = 0; Console.WriteLine("Ange ett antal siffror, separerat med kommatecken"); var input = Console.ReadLine(); @@ -24,6 +25,7 @@ static void Main(string[] args) { numberArray[i] = Convert.ToDouble(inputArray[i]); parsed = true; + intParsedOk++; } catch (Exception) @@ -39,16 +41,24 @@ static void Main(string[] args) dblSum += numberArray[i].Value; } - doubleMid = dblSum / numberArray.Length; + doubleMid = dblSum / intParsedOk; - Console.WriteLine($"Min value is: {numberArray.Min()} Maxvalue is: {numberArray.Max()} Total value is: {dblSum} Midvalue is: {doubleMid}"); + Console.WriteLine($"Min value is: {numberArray.Min()} Maxvalue is: {numberArray.Max()} Total value is: {dblSum} Midvalue is: {doubleMid :f2}"); + + Console.WriteLine("\nPress any key to quit program..."); + Console.ReadKey(true); //for (int i = 0; i < inputArray.Length; i++) //{ - // NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; + // NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; //Bestämmer vilken typ man vill parsa till! + // IFormatProvider formatProvider = new CultureInfo("sv-SE"); //CultureInfo.InvariantCulture; + // IFormatProvider currentNulture = CultureInfo.CurrentCulture;*/ + // bool parsed = double.TryParse(inputArray[i], out double parsedValue); + + //if (parsed == true) //{ // numberArray[i] = parsedValue; @@ -57,7 +67,7 @@ static void Main(string[] args) //{ // numberArray[i] = null; //} - } + } //static double GetDoubleValue(string input) //{