diff --git a/Session02/Session02/Session02.sln b/Session02/Session02/Session02.sln new file mode 100644 index 0000000..678a536 --- /dev/null +++ b/Session02/Session02/Session02.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30413.136 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{F7CC7696-115A-4241-B143-120AB0A3F60B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise02", "Session02Exercise02\Session02Exercise02.csproj", "{F87226E1-856F-4A22-B01A-15C9C2C1B179}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solution02Example04", "Solution02Example04\Solution02Example04.csproj", "{C1FA6E96-F933-45BC-BC22-6BE7ABE72636}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Solution02Example05", "Solution02Example05\Solution02Example05.csproj", "{6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F7CC7696-115A-4241-B143-120AB0A3F60B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7CC7696-115A-4241-B143-120AB0A3F60B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7CC7696-115A-4241-B143-120AB0A3F60B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7CC7696-115A-4241-B143-120AB0A3F60B}.Release|Any CPU.Build.0 = Release|Any CPU + {F87226E1-856F-4A22-B01A-15C9C2C1B179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F87226E1-856F-4A22-B01A-15C9C2C1B179}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F87226E1-856F-4A22-B01A-15C9C2C1B179}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F87226E1-856F-4A22-B01A-15C9C2C1B179}.Release|Any CPU.Build.0 = Release|Any CPU + {C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C1FA6E96-F933-45BC-BC22-6BE7ABE72636}.Release|Any CPU.Build.0 = Release|Any CPU + {6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B150AC3-1C40-4CBA-94DB-F0D6EF27D410}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EF9E92EC-71B2-472F-B2CA-CE53F3040AF9} + EndGlobalSection +EndGlobal diff --git a/Session02/Session02/Session02Exercise01/Program.cs b/Session02/Session02/Session02Exercise01/Program.cs new file mode 100644 index 0000000..452777e --- /dev/null +++ b/Session02/Session02/Session02Exercise01/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace Session02Exercise01 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + + + + + var integer = 0; + string stringValue = "MyStringValue"; + + Console.WriteLine("Integer is " + integer.ToString()); + Console.WriteLine("The value of stringValue is: " + stringValue); + } + } +} diff --git a/Session02/Session02/Session02Exercise01/Session02Exercise01.csproj b/Session02/Session02/Session02Exercise01/Session02Exercise01.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02/Session02Exercise01/Session02Exercise01.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02/Session02Exercise02/Program.cs b/Session02/Session02/Session02Exercise02/Program.cs new file mode 100644 index 0000000..4a344f3 --- /dev/null +++ b/Session02/Session02/Session02Exercise02/Program.cs @@ -0,0 +1,22 @@ +using System; + +namespace Session02Exercise02 +{ + 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; + + Console.WriteLine("\nEnter your name:"); + var name = Console.ReadLine(); + + Console.WriteLine("Hello, " + name); + Console.ReadKey(); + } + } +} diff --git a/Session02/Session02/Session02Exercise02/Session02Exercise02.csproj b/Session02/Session02/Session02Exercise02/Session02Exercise02.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02/Session02Exercise02/Session02Exercise02.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02/Solution02Example04/Program.cs b/Session02/Session02/Solution02Example04/Program.cs new file mode 100644 index 0000000..c3bc330 --- /dev/null +++ b/Session02/Session02/Solution02Example04/Program.cs @@ -0,0 +1,30 @@ +using System; + +namespace Solution02Example04 +{ + 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 tobaksprodukter"); + } + + if (integer >= 40) + { + Console.WriteLine("Du är även jättegammal"); + } + } + } +} diff --git a/Session02/Session02/Solution02Example04/Solution02Example04.csproj b/Session02/Session02/Solution02Example04/Solution02Example04.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02/Solution02Example04/Solution02Example04.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session02/Session02/Solution02Example05/Program.cs b/Session02/Session02/Solution02Example05/Program.cs new file mode 100644 index 0000000..dcc0e83 --- /dev/null +++ b/Session02/Session02/Solution02Example05/Program.cs @@ -0,0 +1,31 @@ +using System; + +namespace Solution02Example05 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Ange vattentemperatur i grader C:"); + + var input = Console.ReadLine(); + var integer = Convert.ToInt32(input); + + string waterLabel = integer >= 27 ? "Går att bada" : "Går inte att bada"; + + // Är samma sak som + //if (integer > 27) + //{ + // waterLabel = "Går att bada"; + //} + //else + //{ + // waterLabel = "Går inte att bada"; + //} + + + + Console.WriteLine(waterLabel + " i havet"); + } + } +} diff --git a/Session02/Session02/Solution02Example05/Solution02Example05.csproj b/Session02/Session02/Solution02Example05/Solution02Example05.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session02/Session02/Solution02Example05/Solution02Example05.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session03/Session03/Session03.sln b/Session03/Session03/Session03.sln new file mode 100644 index 0000000..f62d2a7 --- /dev/null +++ b/Session03/Session03/Session03.sln @@ -0,0 +1,31 @@ + +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}") = "Session03Exercise02", "Session03Exercise02\Session03Exercise02.csproj", "{F8F25BB2-9822-43C4-899B-8102A0552F7D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Numbers", "Session03Numbers\Session03Numbers.csproj", "{DD026B75-D062-4537-988E-204B8C353397}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F8F25BB2-9822-43C4-899B-8102A0552F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8F25BB2-9822-43C4-899B-8102A0552F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8F25BB2-9822-43C4-899B-8102A0552F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8F25BB2-9822-43C4-899B-8102A0552F7D}.Release|Any CPU.Build.0 = Release|Any CPU + {DD026B75-D062-4537-988E-204B8C353397}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD026B75-D062-4537-988E-204B8C353397}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD026B75-D062-4537-988E-204B8C353397}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD026B75-D062-4537-988E-204B8C353397}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7E1D272D-D7F3-42FC-A017-131D73DC1330} + EndGlobalSection +EndGlobal diff --git a/Session03/Session03/Session03Exercise02/Program.cs b/Session03/Session03/Session03Exercise02/Program.cs new file mode 100644 index 0000000..ab8c00c --- /dev/null +++ b/Session03/Session03/Session03Exercise02/Program.cs @@ -0,0 +1,21 @@ +using System; + +namespace Session03Exercise02 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Ange ett antal siffror, separerat med kommatecken."); + var input = Console.ReadLine(); + + var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries); + + foreach (var number in inputArray) + { + Console.WriteLine("Värdet är " + number); + } + + } + } +} diff --git a/Session03/Session03/Session03Exercise02/Session03Exercise02.csproj b/Session03/Session03/Session03Exercise02/Session03Exercise02.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session03/Session03/Session03Exercise02/Session03Exercise02.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + + diff --git a/Session03/Session03/Session03Numbers/Program.cs b/Session03/Session03/Session03Numbers/Program.cs new file mode 100644 index 0000000..c8175b6 --- /dev/null +++ b/Session03/Session03/Session03Numbers/Program.cs @@ -0,0 +1,141 @@ +using System; +using System.Diagnostics; +using System.Globalization; +using System.Linq; + +namespace Session03Numbers +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Ange ett antal siffror, separerat med kommatecken."); + var input = Console.ReadLine(); + + var inputArray = input.Split(",", StringSplitOptions.RemoveEmptyEntries); + + double?[] numbersArray = new double?[inputArray.Length]; + double? sum = 0; + double? largest = 0; + double? smallest = 0; + double? average = 0; + + for (int i = 0; i < inputArray.Length; i++) + { + //try + //{ + + // //Debug.Assert(i < inputArray.Length - 1); + //} + //catch (Exception) + //{ + // numbersArray[i] = 0; + //} + //finally + //{ + + //} + + NumberStyles numberStyle = NumberStyles.Integer | NumberStyles.Float; + + bool parsed = double.TryParse(inputArray[i], numberStyle, CultureInfo.InvariantCulture, out double parsedValue); + + if (parsed) + { + numbersArray[i] = parsedValue; + } + else + { + numbersArray[i] = null; + } + + //numbersArray[i] = Convert.ToDouble(inputArray[i]); + Console.WriteLine("Värde " + numbersArray[i]); + + //sum += numbersArray[i]; + + } + + foreach (double? num in numbersArray) + { + if (num == null) + { + continue; + } + else + { + sum += num; + } + } + + largest = numbersArray.Max(); + smallest = numbersArray.Min(); + average = (float)sum / numbersArray.Length; + + // Option 2 for largest & smallest + largest = numbersArray[0]; + smallest = numbersArray[0]; + + foreach(double? num in numbersArray) + { + if (largest < num) + largest = num; + + if (smallest > num) + smallest = num; + } + + + Console.WriteLine($"\nStörsta värdet: {largest}\nLägsta värdet: {smallest}\n" + + $"Antal tal: {numbersArray.Length}\nMedelvärde: {average}"); + + //int exceptionStatus = getExceptionStatus(); + } + + //static double GetDoubleValue(string input) + //{ + // try + // { + // var result = int.Parse(input); + + // return result; + // } + // catch (FormatException ex) when (ex.Message.Contains("Input string")) + // { + // //throw; + // return double.MinValue; + + // } + // catch (Exception ex) + // { + // return 0; + // } + //} + + //static int getExceptionStatus() + //{ + // int exceptionResult; + + // try + // { + // exceptionResult = -1; + + // throw new Exception("Provocerat fel"); + + // return exceptionResult; + // } + // catch (Exception ex) + // { + // exceptionResult = ex.HResult; + + // return exceptionResult; + + // } + // finally + // { + // exceptionResult = int.MaxValue; + + // } + // } + } +} diff --git a/Session03/Session03/Session03Numbers/Session03Numbers.csproj b/Session03/Session03/Session03Numbers/Session03Numbers.csproj new file mode 100644 index 0000000..c73e0d1 --- /dev/null +++ b/Session03/Session03/Session03Numbers/Session03Numbers.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp3.1 + + +