Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers app #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Session02/Exercise01/Exercise01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
23 changes: 23 additions & 0 deletions Session02/Exercise01/Nameprogram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace Exercise01
{
class Nameprogram
{
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("Enter your name:");
var name = Console.ReadLine();

Console.WriteLine("Hello, " + name);
Console.ReadKey();

}
}
}
31 changes: 31 additions & 0 deletions Session02/Session02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30330.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{7AD8F7EE-EE2F-4406-83B8-175E47A055BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise01", "Exercise01\Exercise01.csproj", "{A006EB6B-4575-4218-8515-908D59C38027}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7AD8F7EE-EE2F-4406-83B8-175E47A055BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AD8F7EE-EE2F-4406-83B8-175E47A055BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AD8F7EE-EE2F-4406-83B8-175E47A055BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AD8F7EE-EE2F-4406-83B8-175E47A055BA}.Release|Any CPU.Build.0 = Release|Any CPU
{A006EB6B-4575-4218-8515-908D59C38027}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A006EB6B-4575-4218-8515-908D59C38027}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A006EB6B-4575-4218-8515-908D59C38027}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A006EB6B-4575-4218-8515-908D59C38027}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A01846C8-7967-4D9C-BFB6-B277CE9B5BFB}
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions Session02/Session02Exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace Session02Exercise01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");


Console.ReadLine();

}
}
}
8 changes: 8 additions & 0 deletions Session02/Session02Exercise01/Session02Exercise01.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Session03/Session03.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30330.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session03Exercise02", "Session03Exercise02\Session03Exercise02.csproj", "{AC8EF63F-B225-4D1A-AB4E-0DED2349D8CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AC8EF63F-B225-4D1A-AB4E-0DED2349D8CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC8EF63F-B225-4D1A-AB4E-0DED2349D8CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC8EF63F-B225-4D1A-AB4E-0DED2349D8CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC8EF63F-B225-4D1A-AB4E-0DED2349D8CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F9EA986A-D463-4C01-AAE3-D2F92EF01A3C}
EndGlobalSection
EndGlobal
64 changes: 64 additions & 0 deletions Session03/Session03Exercise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

using System;
using System.Diagnostics;
using System.Globalization;
using System.Linq;

namespace Session03Exercise02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Ange ett antal siffron, separat med kommatecken.");
var input = Console.ReadLine();

var inputArray = input.Split(',', StringSplitOptions.RemoveEmptyEntries);//new [] för FrameWork
foreach (var number in inputArray)
{
Console.WriteLine("Värdet är " + number);
}

Console.ReadKey();

Console.WriteLine("Ange ett antal siffror, separat med kommatecken.");
var inputNumber = Console.ReadLine();

var inputStringArray = inputNumber.Split(',', StringSplitOptions.RemoveEmptyEntries);//new [] för FrameWork
var numbers = new double[inputStringArray.Length];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prova att använda en nullbar datatyp här för att hålla reda på om Double.TryParse lyckats eller inte. Om man inte gör det påverkas snittet.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double middlevalue = 0;

//while()
for (int i = 0; i < inputStringArray.Length; i++)
{
Console.WriteLine("Värdet är:".PadRight(14) + inputStringArray[i]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Att använda metodaccess direkt följande literaler på detta sättet är något vi anser påverkar läsbarheten i kod.
Vidare så körs operationen PadRight multipla gånger iom att den är placerad i loopen utan att värdet förändras under körning.

Skriv istället:

var label = "Värdet är:";
var paddedLabel = label.PadRight(14);

for (int i = 0; i < inputStringArray.Length; i++)
{
    Console.WriteLine(paddedLabel + inputStringArray[i]);

try
{
double currentNumber = 0;
NumberStyles numberStyles = NumberStyles.Any | NumberStyles.Float; //bitwiseoperator
bool parsed = Double.TryParse(inputStringArray[i], numberStyles, CultureInfo.InvariantCulture, out currentNumber);
if (parsed)
{
numbers[i] = currentNumber;
middlevalue += currentNumber;
}
else continue;

// Debug.Assert(i < numbers.Length - 1);
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}

}
Console.WriteLine("-------------------------------------------\n");
Console.WriteLine($"Högsta värdet: {numbers.Max()}");//Max value
Console.WriteLine($"Minsta värdet: {numbers.Min()}");//Min value
Console.WriteLine("Medelvärdet för arrayen är: " + string.Format($"{(middlevalue / numbers.Length):0.00}")); //Middle value
Console.ReadKey();

}
}
}
8 changes: 8 additions & 0 deletions Session03/Session03Exercise02/Session03Exercise02.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
25 changes: 25 additions & 0 deletions Session2/Session02/Session02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30330.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise01", "Session02Exercise01\Session02Exercise01.csproj", "{D43377BC-B59A-4BC3-9C2B-E8A1E15DECC3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D43377BC-B59A-4BC3-9C2B-E8A1E15DECC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D43377BC-B59A-4BC3-9C2B-E8A1E15DECC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D43377BC-B59A-4BC3-9C2B-E8A1E15DECC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D43377BC-B59A-4BC3-9C2B-E8A1E15DECC3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BE13223B-EA03-4564-8DF3-0ADFF6760509}
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions Session2/Session02/Session02Exercise01/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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);
Console.WriteLine("value of my stringvalue: " + stringValue);

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
1 change: 1 addition & 0 deletions csharp-plus-2020
Submodule csharp-plus-2020 added at f0bd65
1 change: 1 addition & 0 deletions sharp_projects
Submodule sharp_projects added at dfb7d6
1 change: 1 addition & 0 deletions srctreeclone
Submodule srctreeclone added at 217703