First day

This commit is contained in:
2015-06-18 10:52:10 +02:00
parent b28cbf7ad2
commit 1a61a2a7f7
36 changed files with 1566 additions and 0 deletions

20
Anonymous/Anonymous.sln Normal file
View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Anonymous", "Anonymous\Anonymous.csproj", "{86AA6328-3467-4EE2-89D1-75B3CFDD9830}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{86AA6328-3467-4EE2-89D1-75B3CFDD9830}.Debug|x86.ActiveCfg = Debug|x86
{86AA6328-3467-4EE2-89D1-75B3CFDD9830}.Debug|x86.Build.0 = Debug|x86
{86AA6328-3467-4EE2-89D1-75B3CFDD9830}.Release|x86.ActiveCfg = Release|x86
{86AA6328-3467-4EE2-89D1-75B3CFDD9830}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{86AA6328-3467-4EE2-89D1-75B3CFDD9830}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Anonymous</RootNamespace>
<AssemblyName>Anonymous</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Anonymous
{
class Program
{
static void Main(string[] args)
{
var anonymous = new
{
UserName = "MrRogers",
RegisterDate = DateTime.Now
};
Console.WriteLine(anonymous.UserName);
WaitForInput();
}
public static void WaitForInput()
{
Console.WriteLine("Press a key...");
Console.ReadLine();
}
}
}

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("Anonymous")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Anonymous")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("1bfc1dee-911c-4a88-a547-00c6c9153ed7")]
// 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,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleSlask", "ConsoleSlask\ConsoleSlask.csproj", "{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}.Debug|x86.ActiveCfg = Debug|x86
{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}.Debug|x86.Build.0 = Debug|x86
{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}.Release|x86.ActiveCfg = Release|x86
{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleSlask</RootNamespace>
<AssemblyName>ConsoleSlask</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleSlask
{
class Program
{
public struct Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int YearOfBirth;
// En låtsas-konstruktor för en Struct
public Person(string firstName, string lastName, int yearOfBirth)
: this()
{
FirstName = firstName;
LastName = lastName;
YearOfBirth = yearOfBirth;
}
}
static void WaitForInput()
{
Console.WriteLine("Press Enter...");
Console.ReadLine();
}
private static void PrintPerson(Person p)
{
Console.WriteLine("FirstName: " + p.FirstName);
Console.WriteLine("LastName: " + p.LastName);
Console.WriteLine("YearOfBirth: " + p.YearOfBirth);
WaitForInput();
}
static void Main()
{
Console.WriteLine("Hello World!");
Person p = new Person(firstName: "Christian", lastName: "Ohlsson", yearOfBirth: 1973);
PrintPerson(p);
}
}
}

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("ConsoleSlask")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleSlask")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("141603f2-c738-4c70-99c5-2b43418ab956")]
// 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")]

42
Exercise1/Exercise1.sln Normal file
View File

@@ -0,0 +1,42 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise1", "Exercise1\Exercise1.csproj", "{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StoreData", "StoreData\StoreData.csproj", "{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Debug|Any CPU.ActiveCfg = Debug|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Debug|Mixed Platforms.Build.0 = Debug|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Debug|x86.ActiveCfg = Debug|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Debug|x86.Build.0 = Debug|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Release|Any CPU.ActiveCfg = Release|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Release|Mixed Platforms.ActiveCfg = Release|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Release|Mixed Platforms.Build.0 = Release|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Release|x86.ActiveCfg = Release|x86
{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}.Release|x86.Build.0 = Release|x86
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Debug|x86.ActiveCfg = Debug|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Release|Any CPU.Build.0 = Release|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,27 @@
using StoreData;
namespace Exercise1
{
public class Account : IAccount
{
private decimal balance = 0;
public decimal Balance
{
get { return balance; }
}
public void Add(decimal amount)
{
balance += amount;
}
public void Remove(decimal amount)
{
if (!(amount > balance))
{
balance -= amount;
}
}
}
}

View File

@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BE0E4F97-1C52-4DD1-9229-10CDDFB6661F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercise1</RootNamespace>
<AssemblyName>Exercise1</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Account.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ShoppingCart.cs" />
<Compile Include="ShoppingDemo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StoreData\StoreData.csproj">
<Project>{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}</Project>
<Name>StoreData</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,23 @@
using System;
using System.Linq;
using System.Text;
namespace Exercise1
{
class Program
{
static void Main(string[] args)
{
// Setup a test account
var account = new Account();
account.Add(1500);
// Create an empty shopping cart
var cart = new ShoppingCart();
// Run the demo
var demo = new ShoppingDemo(cart, account);
demo.Run();
}
}
}

View File

@@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Resources;
// 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("Exercise1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Exercise1.Properties")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("7A332E26-38F4-4649-B445-3BAFDBD15431")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: NeutralResourcesLanguageAttribute("sv-SE")]

View File

@@ -0,0 +1,47 @@
using System.Collections.Generic;
using StoreData;
namespace Exercise1
{
public class ShoppingCart : IShoppingCart
{
private List<Product> products = new List<Product>();
public void AddProduct(Product p)
{
products.Add(p);
}
public void RemoveProductByNumber(int index)
{
products.RemoveAt(index);
}
public void Clear()
{
products.Clear();
}
public decimal TotalSum()
{
decimal sum = 0;
foreach (var product in Products)
{
sum += product.Price;
}
return sum;
}
public bool CartIsEmpty()
{
return (products.Count == 0);
}
public List<Product> Products
{
get { return products; }
}
}
}

View File

@@ -0,0 +1,293 @@
using System;
using System.Collections.Generic;
using StoreData;
namespace Exercise1
{
public class ShoppingDemo
{
private IShoppingCart cart;
private IAccount account;
private List<Product> store;
/// <summary>
/// Constructor
/// </summary>
/// <param name="cart"></param>
/// <param name="account"></param>
public ShoppingDemo(IShoppingCart cart, IAccount account)
{
PopulateStore();
this.cart = cart;
this.account = account;
}
/// <summary>
/// Populate the store with a bunch of book titles
/// </summary>
private void PopulateStore()
{
store = new List<Product>
{
new Product {Name = "Professional C# 4 and .NET 4", Price = 354},
new Product {Name = "Beginning ASP.NET E-Commerce in C#", Price = 260},
new Product {Name = "Objektorienterad analys och design", Price = 418},
new Product {Name = "Improving Software Organizations", Price = 486},
new Product {Name = "Operating System Concepts", Price = 514},
new Product {Name = "Compilers: Principles, techniques and Tools", Price = 1265},
new Product {Name = "Pro Git", Price = 221},
new Product {Name = "Design Patterns", Price = 315}
};
}
/// <summary>
/// Run the demo application
/// </summary>
public void Run()
{
var running = true;
while (running)
{
PrintMainMenu();
var input = Console.ReadLine();
if (input == "6")
running = false;
else
MakeChoice(input);
}
}
/// <summary>
/// Make a choice from the main menu
/// </summary>
/// <param name="input"></param>
private void MakeChoice(string input)
{
switch (input)
{
case "1":
AddProductDialog();
break;
case "2":
RemoveProductDialog();
break;
case "3":
EmptyShoppingCartDialog();
break;
case "4":
ListProductsDialog();
break;
case "5":
PaymentDialog();
break;
}
}
/// <summary>
/// Print a list of all products
/// </summary>
private void ListProductsDialog()
{
Console.Clear();
Console.WriteLine("List of all products in shopping cart:");
Console.WriteLine("--------------------------------------");
Console.WriteLine();
var listOfProducts = cart.Products;
if (listOfProducts.Count == 0)
Console.WriteLine("-- The shopping cart is empty --");
for (int i=0; i<listOfProducts.Count; i++)
{
Console.WriteLine("{0}) {1}.PRICE: {2} SEK", i+1, listOfProducts[i].Name, listOfProducts[i].Price);
}
Console.WriteLine();
WaitForInput();
}
/// <summary>
/// Shown when it's time to pay
/// </summary>
private void PaymentDialog()
{
Console.Clear();
if (cart.CartIsEmpty())
{
Console.WriteLine("\n -- The cart is empty, you have nothing to pay yet. --\n");
WaitForInput();
return;
}
var sum = cart.TotalSum();
Console.WriteLine("TOTAL : " + sum);
Console.WriteLine("YOUR BALANCE: " + account.Balance);
Console.WriteLine();
if (sum > account.Balance)
{
Console.WriteLine("We're sorry, but you don't have enough funds on your account");
}
else
{
Console.Write("Do you want to pay? (y/n) ");
var input = Console.ReadLine();
if (input.ToLower() == "n")
return;
Console.WriteLine("Thank you! Your order has been processed!");
account.Remove(sum);
cart.Clear();
}
WaitForInput();
}
/// <summary>
/// Clear the shopping cart
/// </summary>
private void EmptyShoppingCartDialog()
{
cart.Clear();
Console.Clear();
Console.WriteLine();
Console.WriteLine(" -- Cleared shopping cart --");
Console.WriteLine();
WaitForInput();
}
/// <summary>
/// Shown when removing a product
/// </summary>
private void RemoveProductDialog()
{
Console.Clear();
Console.WriteLine("List of all products in shopping cart:");
Console.WriteLine("--------------------------------------");
Console.WriteLine();
var listOfProducts = cart.Products;
if (listOfProducts.Count == 0)
{
Console.WriteLine("-- The shopping cart is empty --\n");
WaitForInput();
return;
}
for (int i = 0; i < listOfProducts.Count; i++)
{
Console.WriteLine("{0}) {1}.PRICE: {2} SEK", i + 1, listOfProducts[i].Name, listOfProducts[i].Price);
}
Console.WriteLine();
Console.Write("Select an item to REMOVE: ");
var input = Console.ReadLine();
int coercedInput;
if (!int.TryParse(input, out coercedInput))
{
Console.WriteLine("Must enter a number!");
}
else
{
var products = cart.Products;
if (coercedInput > products.Count || coercedInput <= 0)
Console.WriteLine("Not a valid number!");
else
{
cart.RemoveProductByNumber(coercedInput-1);
Console.WriteLine("Removed item from cart!");
}
}
Console.WriteLine();
WaitForInput();
}
/// <summary>
/// The dialogue shown when adding a product to the cart
/// </summary>
private void AddProductDialog()
{
Console.Clear();
Console.WriteLine("Products in store");
Console.WriteLine("-----------------");
Console.WriteLine();
for (int i = 0; i < store.Count; i++)
{
Console.WriteLine("{0}) {1}. PRICE: {2} SEK", i+1, store[i].Name, store[i].Price);
}
Console.WriteLine();
Console.Write("Enter a product number: ");
var input = Console.ReadLine();
int coercedInput;
if (!int.TryParse(input, out coercedInput))
{
Console.WriteLine("Must enter a number!");
}
else
{
if (coercedInput > store.Count || coercedInput <= 0)
Console.WriteLine("Not a valid number!");
else
{
cart.AddProduct(store[coercedInput-1]);
Console.WriteLine("Added Item!");
}
}
WaitForInput();
}
/// <summary>
/// Shows the main menu
/// </summary>
public void PrintMainMenu()
{
Console.Clear();
Console.WriteLine("Main Menu");
Console.WriteLine("---------");
Console.WriteLine("YOUR BALANCE: " + account.Balance);
Console.WriteLine("TOTAL: " + cart.TotalSum());
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("1. Add product to shopping cart");
Console.WriteLine("2. Remove product from shopping cart");
Console.WriteLine("3. Empty shopping cart");
Console.WriteLine("4. List products in shopping cart");
Console.WriteLine("5. Pay");
Console.WriteLine("6. Exit");
Console.WriteLine();
Console.Write("Make a choice: ");
}
/// <summary>
/// Just a method to wait for the user to press enter
/// </summary>
private void WaitForInput()
{
Console.WriteLine("Press Enter...");
Console.ReadLine();
}
}
}

View File

@@ -0,0 +1,22 @@
namespace StoreData
{
public interface IAccount
{
/// <summary>
/// Check the balance
/// </summary>
decimal Balance { get; }
/// <summary>
/// Add money to this account
/// </summary>
/// <param name="amount">The amount to add</param>
void Add(decimal amount);
/// <summary>
/// Remove money from this account
/// </summary>
/// <param name="amount">The amount to remove</param>
void Remove(decimal amount);
}
}

View File

@@ -0,0 +1,37 @@
using System.Collections.Generic;
namespace StoreData
{
public interface IShoppingCart
{
/// <summary>
/// This method adds a product to the shopping cart
/// </summary>
/// <param name="p">The product to add</param>
void AddProduct(Product p);
/// <summary>
/// Remove product by number
/// </summary>
/// <param name="index">The index of the product to remove</param>
void RemoveProductByNumber(int index);
/// <summary>
/// Clears the entire shopping cart
/// </summary>
void Clear();
/// <summary>
/// Calculate the sum of the cost of all products
/// </summary>
/// <returns></returns>
decimal TotalSum();
/// <summary>
/// Returns true if cart is empty, otherwise false
/// </summary>
bool CartIsEmpty();
List<Product> Products { get; }
}
}

View File

@@ -0,0 +1,8 @@
namespace StoreData
{
public class Product
{
public decimal Price { get; set; }
public string Name { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
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("StoreData.Properties")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StoreData.Properties")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("7A332E26-38F4-4649-B445-3BAFDBD15431")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{A3587AB8-ED1A-4C9F-9981-42863DB18AF9}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>StoreData</RootNamespace>
<AssemblyName>StoreData</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<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' ">
<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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="IAccount.cs" />
<Compile Include="IShoppingCart.cs" />
<Compile Include="Product.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

20
Exercise2A/Exercise2A.sln Normal file
View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise2A", "Exercise2A\Exercise2A.csproj", "{5C9176E5-EFC6-4B86-857B-C687192BDE9B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C9176E5-EFC6-4B86-857B-C687192BDE9B}.Debug|x86.ActiveCfg = Debug|x86
{5C9176E5-EFC6-4B86-857B-C687192BDE9B}.Debug|x86.Build.0 = Debug|x86
{5C9176E5-EFC6-4B86-857B-C687192BDE9B}.Release|x86.ActiveCfg = Release|x86
{5C9176E5-EFC6-4B86-857B-C687192BDE9B}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise2A
{
class CustomStack<T>
{
private List<T> items = new List<T>();
public T Peek()
{
T item = items[0];
return item;
}
public T Pop()
{
T item = items[0];
items.RemoveAt(0);
return item;
}
public T Push(T item)
{
items.Insert(0, item);
return item;
}
private bool isEmpty()
{
if (items.Count == 0)
return true;
else
return false;
}
}
}

View File

@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5C9176E5-EFC6-4B86-857B-C687192BDE9B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercise2A</RootNamespace>
<AssemblyName>Exercise2A</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CustomStack.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise2A
{
class Program
{
static void Main(string[] args)
{
CustomStack<int> intStack = new CustomStack<int>();
CustomStack<string> stringStack = new CustomStack<string>();
/* ------ INT-STACK --------------- */
intStack.Push(14);
intStack.Push(23);
intStack.Push(34);
intStack.Push(46);
Console.WriteLine(intStack.Peek());
intStack.Pop();
Console.WriteLine(intStack.Peek());
/* ------ STRING-STACK --------------- */
stringStack.Push("Anna");
stringStack.Push("Bertil");
stringStack.Push("Ceasar");
Console.WriteLine(stringStack.Peek());
stringStack.Pop();
Console.WriteLine(stringStack.Peek());
WaitForInput();
}
static void WaitForInput()
{
Console.WriteLine("Press Enter...");
Console.ReadLine();
}
}
}

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("Exercise2A")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Exercise2A")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("140ec0cb-89f5-4616-afaa-476f8235b4f5")]
// 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")]

20
Exercise3/Exercise3.sln Normal file
View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise3", "Exercise3\Exercise3.csproj", "{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}.Debug|x86.ActiveCfg = Debug|x86
{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}.Debug|x86.Build.0 = Debug|x86
{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}.Release|x86.ActiveCfg = Release|x86
{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{CBA419E5-E29B-4B4F-A2EA-7721D3701FDA}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercise3</RootNamespace>
<AssemblyName>Exercise3</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ListLoader.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="languages.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Exercise3
{
public class ListLoader
{
public List<string> LoadListFromFile(string fileName)
{
var list = new List<string>();
var sr = new StreamReader(fileName);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
list.Add(line);
}
sr.Close();
return list;
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise3
{
class Program
{
static void Main()
{
ListLoader myLoader = new ListLoader();
List<string> languages = new List<string>();
languages = myLoader.LoadListFromFile("languages.txt");
Console.Write("List languages containing: ");
string searchFor = Console.ReadLine();
var result = from a in languages
where a.ToLower().Contains(searchFor.ToLower())
select a;
foreach (var item in result)
{
Console.WriteLine(item);
}
WaitForInput();
}
static void WaitForInput()
{
Console.WriteLine("Press Enter...");
Console.ReadLine();
}
}
}

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("Exercise3")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Exercise3")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("b83c9f9b-6ba5-4223-835c-4b62f07d8381")]
// 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")]

20
Exercise4/Exercise4.sln Normal file
View File

@@ -0,0 +1,20 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exercise4", "Exercise4\Exercise4.csproj", "{10C24B0F-B14A-4CDD-8393-A657B18CE39F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{10C24B0F-B14A-4CDD-8393-A657B18CE39F}.Debug|x86.ActiveCfg = Debug|x86
{10C24B0F-B14A-4CDD-8393-A657B18CE39F}.Debug|x86.Build.0 = Debug|x86
{10C24B0F-B14A-4CDD-8393-A657B18CE39F}.Release|x86.ActiveCfg = Release|x86
{10C24B0F-B14A-4CDD-8393-A657B18CE39F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{10C24B0F-B14A-4CDD-8393-A657B18CE39F}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercise4</RootNamespace>
<AssemblyName>Exercise4</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</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|x86' ">
<PlatformTarget>x86</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.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="LanguageData.cs" />
<Compile Include="ListLoader.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise4
{
class LanguageData
{
public string Name;
public int Year;
public string Description;
}
}

View File

@@ -0,0 +1,31 @@

using System.Collections.Generic;
using System.IO;
namespace Exercise4
{
class ListLoader {
public List<LanguageData> LoadListFromFile(string fileName)
{
var list = new List<LanguageData>();
var sr = new StreamReader(fileName);
var line = string.Empty;
while ((line = sr.ReadLine()) != null)
{
LanguageData OneLineOfData = new LanguageData();
string [] temp = line.Split('\t');
OneLineOfData.Name = temp[0];
OneLineOfData.Year = int.Parse(temp[1]);
OneLineOfData.Description = temp[2];
list.Add(OneLineOfData);
}
sr.Close();
return list;
}
}
}

View File

@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Exercise4
{
class Program
{
static void Main()
{
ListLoader myLoader = new ListLoader();
List<LanguageData> languages = new List<LanguageData>();
languages = myLoader.LoadListFromFile("languageData.txt");
Console.Write("Minimum Year: ");
string minimumYear = Console.ReadLine();
Console.Write("Maximum Year: ");
string maximumYTear = Console.ReadLine();
var result = from a in languages
where a.Year > int.Parse(minimumYear) && a.Year < int.Parse(maximumYTear)
orderby a.Year
select new { a.Name, a.Year};
Console.WriteLine("\nRESULTS");
Console.WriteLine("======================");
foreach (var item in result)
{
Console.WriteLine(item.Name + " (" + item.Year + ")");
}
WaitForInput();
}
static void WaitForInput()
{
Console.WriteLine("\nPress Enter...");
Console.ReadLine();
}
}
}

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("Exercise4")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Exercise4")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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("c11686f9-270c-4b7a-bf0b-c65a72be467e")]
// 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")]