Ass 3 Task 3-4

This commit is contained in:
Philip Johansson 2022-07-04 11:48:33 +02:00
parent dabcc3e72c
commit ab62aef528
36 changed files with 491 additions and 2 deletions

Binary file not shown.

View File

@ -7,6 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Task1", "Task1\Task1.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task2", "Task2\Task2.csproj", "{334B64F4-F344-448D-ADC9-95D759151758}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task3", "Task3\Task3.csproj", "{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Task4", "Task4\Task4.csproj", "{C857EB2B-41A9-4D5A-B660-58E88609C83C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +25,14 @@ Global
{334B64F4-F344-448D-ADC9-95D759151758}.Debug|Any CPU.Build.0 = Debug|Any CPU
{334B64F4-F344-448D-ADC9-95D759151758}.Release|Any CPU.ActiveCfg = Release|Any CPU
{334B64F4-F344-448D-ADC9-95D759151758}.Release|Any CPU.Build.0 = Release|Any CPU
{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}.Release|Any CPU.Build.0 = Release|Any CPU
{C857EB2B-41A9-4D5A-B660-58E88609C83C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C857EB2B-41A9-4D5A-B660-58E88609C83C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C857EB2B-41A9-4D5A-B660-58E88609C83C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C857EB2B-41A9-4D5A-B660-58E88609C83C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Task2
{
internal class Program
internal class Task2
{
static void Main(string[] args)
{

View File

@ -43,7 +43,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Task2.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Task3
{
internal class Program
{
static void Main(string[] args)
{
var availableModels = new List<string> { "Camber Comp", "Challenger", "Discovery", "Electric" };
var availableSizes = new List<string> { "S", "M", "L", "XL" };
var bikes = new List<Bicycle>();
var rnd = new Random();
for (int i = 1; i <= 10; i++)
{
var randomFrameSizeListIndex = rnd.Next(availableSizes.Count);
var randomModelListIndex = rnd.Next(availableModels.Count);
bikes.Add(new Bicycle(availableModels[randomModelListIndex], availableSizes[randomFrameSizeListIndex]));
//Console.WriteLine($"The list now has {bikes.Count} members and the last added was {bikes.Last().Id}");
}
Console.WriteLine("Bikes have been created");
printInfo(bikes);
Console.WriteLine();
Console.WriteLine("Accelerating...");
foreach (var item in bikes)
{
int speed = rnd.Next(10, 50);
item.Speed = speed;
}
printInfo(bikes);
while (Console.ReadKey().ToString().Equals("Q"))
{
System.Threading.Thread.Sleep(1000);
}
}
static void printInfo(List<Bicycle> bikes)
{
const int columnWidth = -20;
Console.WriteLine("Listing all bicycles:");
Console.WriteLine($"{"Serial Number",columnWidth}" + $"{"Model",columnWidth}" + $"{"Frame Size",columnWidth}" + $"{"Speed",columnWidth}");
foreach (var item in bikes)
{
Console.WriteLine($"{item.Id,columnWidth}" + $"{item.Model,columnWidth}" + $"{item.Size,columnWidth}" + $"{item.Speed,columnWidth}");
}
}
}
class Bicycle
{
// Variable shared by all intances
private static int _incrementalId = 1000;
private int _id;
private int _speed;
private string _model;
private string _size;
public Bicycle(string model, string frameSize = "M")
{
_incrementalId += 1;
_id = _incrementalId;
//Console.WriteLine($"Incremental ID is {_id}");
_speed = 0;
_model = model;
_size = frameSize;
}
public int Id
{
get { return _id; }
}
public string Size
{
get { return _size; }
}
public int Speed
{
set
{
if (value >= 0)
_speed = value;
else
_speed = 0;
}
get
{
return _speed;
}
}
public string Model
{
get => _model;
}
public bool accelerate()
{
int increase = 5;
if (this._speed + increase >= 100)
return false;
this._speed += increase;
return true;
}
public bool brake()
{
int decrease = 5;
if (this._speed - decrease <= 0)
return false;
this._speed -= decrease;
return true;
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Task3")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Task3")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1e6acf64-12ff-46e4-88a9-1487e83ae34a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{1E6ACF64-12FF-46E4-88A9-1487E83AE34A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Task3</RootNamespace>
<AssemblyName>Task3</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Binary file not shown.

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

View File

@ -0,0 +1 @@
7f4b213b428f4c013f19137338418ee1f5525793

View File

@ -0,0 +1,8 @@
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\bin\Debug\Task3.exe.config
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\bin\Debug\Task3.exe
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\bin\Debug\Task3.pdb
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\obj\Debug\Task3.csproj.AssemblyReference.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\obj\Debug\Task3.csproj.SuggestedBindingRedirects.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\obj\Debug\Task3.csproj.CoreCompileInputs.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\obj\Debug\Task3.exe
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task3\obj\Debug\Task3.pdb

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

View File

@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Task4
{
internal class Program
{
static void Main(string[] args)
{
for (; ; )
{
Console.WriteLine("Welcome!");
int currentYear = DateTime.Now.Year;
Console.WriteLine("State your first name or enter \"q\" to exit");
var firstName = Console.ReadLine();
if (firstName == "q")
return;
Console.WriteLine("State your last name: ");
var lastName = Console.ReadLine();
if (lastName == "q")
return;
Console.WriteLine("State your year of birth with 4 digits: ");
int yearOfBirth;
// Cannot be born in the future or be above 100 years old
bool validYear(int year)
{
return year > currentYear - 100 && year <= currentYear;
}
while (!(int.TryParse(Console.ReadLine(), out yearOfBirth) && validYear(yearOfBirth)))
{
Console.WriteLine("Invalid year of birth try again");
}
var heartRates = new HeartRates(firstName, lastName, yearOfBirth, currentYear);
Console.WriteLine($"Hello {heartRates.FirstName} {heartRates.LastName}");
Console.WriteLine($"Your age is {heartRates.age()} and maximum heart rate is {heartRates.maxHeartRate()}");
Console.WriteLine($"Your target heart rate is between {heartRates.minTargetRange()} and {heartRates.maxTargetRange()}")
}
}
}
class HeartRates
{
private string _firstName;
private string _lastName;
private int _yearOfBirth;
private int _currentYear;
//private TargetRange _targetRange;
// private Tuple<int, int> _targetRange2;
//public struct TargetRange
//{
// private double _min;
// private double _max;
// public TargetRange(int age)
// : this()
// {
// double maxHeartrate = 220 - (double)age;
// _min = maxHeartrate * 0.5;
// _max = maxHeartrate * 0.85;
// }
// public double Min { get; }
// public double Max { get; }
//}
public HeartRates(string firstName,
string lastName,
int yearofBirth,
int currentYear)
{
_firstName = firstName;
_lastName = lastName;
_yearOfBirth = yearofBirth;
_currentYear = currentYear;
//_targetRange = new TargetRange(currentYear - yearofBirth);
}
public string FirstName
{
set { _firstName = value; }
get => _firstName;
}
public string LastName
{
set { _lastName = value; }
get => _lastName;
}
public int YearOfBirth { set; get; }
//public TargetRange PersonalTargetRange { get {return _targetRange;} }
public int age()
{
return _currentYear - _yearOfBirth;
}
public double maxHeartRate()
{
return 220 - (double)age();
}
public double minTargetRange()
{
return maxHeartRate() * 0.5;
}
public double maxTargetRange()
{
return maxHeartRate() * 0.85;
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Task4")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Task4")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c857eb2b-41a9-4d5a-b660-58e88609c83c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{C857EB2B-41A9-4D5A-B660-58E88609C83C}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Task4</RootNamespace>
<AssemblyName>Task4</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Binary file not shown.

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

Binary file not shown.

View File

@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]

View File

@ -0,0 +1 @@
7f4b213b428f4c013f19137338418ee1f5525793

View File

@ -0,0 +1,8 @@
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\bin\Debug\Task4.exe.config
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\bin\Debug\Task4.exe
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\bin\Debug\Task4.pdb
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\obj\Debug\Task4.csproj.AssemblyReference.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\obj\Debug\Task4.csproj.SuggestedBindingRedirects.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\obj\Debug\Task4.csproj.CoreCompileInputs.cache
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\obj\Debug\Task4.exe
D:\Git\Bashir C-sharp assignments\Module3-Assignments\Task4\obj\Debug\Task4.pdb

Binary file not shown.

Binary file not shown.