Skip to content

Number app #19

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
File renamed without changes.
49 changes: 49 additions & 0 deletions csharp Project 2020/Session02/Session02.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

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", "{90D33783-F27C-47B3-928D-EB236817F121}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Session02Execise02", "Session02Execise02\Session02Execise02.csproj", "{A4100873-7111-432C-9C9D-3A2B02B5741E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise03", "Session02Exercise03\Session02Exercise03.csproj", "{143EC31C-40E9-442E-9D3C-27C2617B3033}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise04", "Session02Exercise04\Session02Exercise04.csproj", "{CE77F64E-455D-41A9-B510-A7C3F2F891D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Session02Exercise05", "Session02Exercise05\Session02Exercise05.csproj", "{1FD0DCB2-5043-498B-AAE3-2CAF99478E27}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{90D33783-F27C-47B3-928D-EB236817F121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{90D33783-F27C-47B3-928D-EB236817F121}.Debug|Any CPU.Build.0 = Debug|Any CPU
{90D33783-F27C-47B3-928D-EB236817F121}.Release|Any CPU.ActiveCfg = Release|Any CPU
{90D33783-F27C-47B3-928D-EB236817F121}.Release|Any CPU.Build.0 = Release|Any CPU
{A4100873-7111-432C-9C9D-3A2B02B5741E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4100873-7111-432C-9C9D-3A2B02B5741E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4100873-7111-432C-9C9D-3A2B02B5741E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4100873-7111-432C-9C9D-3A2B02B5741E}.Release|Any CPU.Build.0 = Release|Any CPU
{143EC31C-40E9-442E-9D3C-27C2617B3033}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{143EC31C-40E9-442E-9D3C-27C2617B3033}.Debug|Any CPU.Build.0 = Debug|Any CPU
{143EC31C-40E9-442E-9D3C-27C2617B3033}.Release|Any CPU.ActiveCfg = Release|Any CPU
{143EC31C-40E9-442E-9D3C-27C2617B3033}.Release|Any CPU.Build.0 = Release|Any CPU
{CE77F64E-455D-41A9-B510-A7C3F2F891D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CE77F64E-455D-41A9-B510-A7C3F2F891D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE77F64E-455D-41A9-B510-A7C3F2F891D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE77F64E-455D-41A9-B510-A7C3F2F891D3}.Release|Any CPU.Build.0 = Release|Any CPU
{1FD0DCB2-5043-498B-AAE3-2CAF99478E27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1FD0DCB2-5043-498B-AAE3-2CAF99478E27}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1FD0DCB2-5043-498B-AAE3-2CAF99478E27}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1FD0DCB2-5043-498B-AAE3-2CAF99478E27}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E81B455C-C0E0-4277-9839-3E0474FBC01C}
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions csharp Project 2020/Session02/Session02Execise02/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Session02Execise02
{
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("Hello, enter your name:");
var name = Console.ReadLine();

Console.WriteLine("Hello," + name + "!");
Console.ReadKey();
}
}
}
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>
19 changes: 19 additions & 0 deletions csharp Project 2020/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.ToString());
Console.WriteLine("The value of stringValue is:" + 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>
87 changes: 87 additions & 0 deletions csharp Project 2020/Session02/Session02Exercise03/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using System;

namespace Session02Exercise03
{
class Program
{
static void Main(string[] args)
{
//Binary operation
var additionResult = 1 * 2;

Console.WriteLine("additionResult " + additionResult.ToString());

var incrementResult = ++additionResult;

Console.WriteLine("IncrementResult " + incrementResult.ToString());

var trueValue = true;

var falseValue = false;

var andResult = 0b0010 & 0b0100; //0b110;
var orResult = trueValue | falseValue;
var xorResult = trueValue ^ falseValue;

Console.WriteLine("andResult " + andResult);
Console.WriteLine("orResult " + orResult);
Console.WriteLine("xorResult " + xorResult);

var moduloResult = 3 % 2;

Console.WriteLine("ModuloResult " + moduloResult);

var highInterger = 1000;
var intergerDivisionResult = highInterger / 3;

// Implicit värdekonvertering till double
var doubleDivisionResult = highInterger / 3.0;

Console.WriteLine("integerDivisionResult " + intergerDivisionResult);
Console.WriteLine("doubleDivisionResult " + doubleDivisionResult);

int castIntDivisionResult = (int)(highInterger / 3.0);

Console.WriteLine("castIntDivisionResult " + castIntDivisionResult);

var conversionResult = Convert.ToInt32(doubleDivisionResult);

Console.WriteLine("conversionResult " + doubleDivisionResult);


var midpointDivisionResult = 10.0 / 3.0;

Console.WriteLine("midpointDivisionResult " + midpointDivisionResult);
Console.WriteLine("castToInt " + ((int)midpointDivisionResult).ToString());
Console.WriteLine("ceiling " + Math.Ceiling(midpointDivisionResult));
Console.WriteLine("floor " + Math.Floor(midpointDivisionResult));
Console.WriteLine("round " + Math.Round(midpointDivisionResult, 3));

//Det går även att använda sammanslagna operatorer likt följande
additionResult += 2;
additionResult -= 2;
additionResult /= 2;
additionResult *= 2;

var greaterResult = 5 > 3;
var lesstThanResult = 5 < 3;
var greaterOrEqual = 5 >= 5;
var lessOrEqual = 3 <= 5;

Console.WriteLine("greaterResult" + greaterResult);
Console.WriteLine("lessThanResult" + lesstThanResult);
Console.WriteLine("greaterOrEqual" + greaterOrEqual);
Console.WriteLine("lessOrEqual" + lessOrEqual);

var andOperationResult = true && false;
var orOperationResult = true || false;

Console.WriteLine("andOperationResult" + greaterResult);
Console.WriteLine("orOperationResult" + lesstThanResult);



Console.ReadKey();
}
}
}
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>
35 changes: 35 additions & 0 deletions csharp Project 2020/Session02/Session02Exercise04/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace Session02Exercise04
{
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 tobakprodukter");


Comment on lines +18 to +19
Copy link
Owner

Choose a reason for hiding this comment

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

Försök att inte ha för mycket tomutrymme i kodblocken. } bör komma redan på rad 18.

}
else
{
Console.WriteLine("Du får inte köpa tobaksprodukter");

}

if (integer >= 40)
{
Console.WriteLine("Du är också väldigt gammal!");
}


}
}
}
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>
37 changes: 37 additions & 0 deletions csharp Project 2020/Session02/Session02Exercise05/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace Session02Exercise05
{
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";

//Samma sak som
//if (integer > 27)
//{
// waterLabel = "Det går att bada!"
// }
// else
//{
// waterLabel = "Nej! BADA FÖR FAN INTE!!"
//}

switch (integer)
{
//Det går bra att radbyta, men är fular och svårare att läsa
case 1: waterLabel = "går inte att bada alls"; break;
case -3: waterLabel = "Det är 3 minusgrader"; break;
default: /* Här kan man göra något om inget träffar */ break;


}
}
}
}
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace Session03
{
class Program
{
static void Main(string[] args)
{
int[] integerValues = new[] { 1, 2, 3 };

for (var i = 0; i < integerValues.Length; i++)
{
var name = nameof(integerValues);
var value = integerValues[i];

Console.WriteLine($"Index {i} i arrayen {integerValues} har värdet: {value}");

}
var doWhileIndex = 0;

do
{
var value = integerValues[doWhileIndex];

Console.WriteLine($"Index {doWhileIndex} i arrayen {integerValueName}");
doWhileIndex++;
}
while (doWhileIndex < integerValues.Length);

var whileIndex = 0;

while (whileIndex < integerValues.Length)
{
var value = integerValues[whileIndex];

Console.WriteLine($"While Index {whileIndex} i arrayen {integerValuesName} har värdet {value}");

whileIndex++;
}
}
}
}
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>
Loading