diff --git a/Anonymous/Anonymous.sln b/Anonymous/Anonymous.sln new file mode 100644 index 0000000..64850a0 --- /dev/null +++ b/Anonymous/Anonymous.sln @@ -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 diff --git a/Anonymous/Anonymous/Anonymous.csproj b/Anonymous/Anonymous/Anonymous.csproj new file mode 100644 index 0000000..e3d732a --- /dev/null +++ b/Anonymous/Anonymous/Anonymous.csproj @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {86AA6328-3467-4EE2-89D1-75B3CFDD9830} + Exe + Properties + Anonymous + Anonymous + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Anonymous/Anonymous/Program.cs b/Anonymous/Anonymous/Program.cs new file mode 100644 index 0000000..b68241b --- /dev/null +++ b/Anonymous/Anonymous/Program.cs @@ -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(); + } + } +} diff --git a/Anonymous/Anonymous/Properties/AssemblyInfo.cs b/Anonymous/Anonymous/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6bc0b07 --- /dev/null +++ b/Anonymous/Anonymous/Properties/AssemblyInfo.cs @@ -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")] diff --git a/ConsoleSlask/ConsoleSlask.sln b/ConsoleSlask/ConsoleSlask.sln new file mode 100644 index 0000000..dca6131 --- /dev/null +++ b/ConsoleSlask/ConsoleSlask.sln @@ -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 diff --git a/ConsoleSlask/ConsoleSlask/ConsoleSlask.csproj b/ConsoleSlask/ConsoleSlask/ConsoleSlask.csproj new file mode 100644 index 0000000..abec091 --- /dev/null +++ b/ConsoleSlask/ConsoleSlask/ConsoleSlask.csproj @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {F2645C62-5C7B-4D91-83B3-E3CDCC8B0A7D} + Exe + Properties + ConsoleSlask + ConsoleSlask + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ConsoleSlask/ConsoleSlask/Program.cs b/ConsoleSlask/ConsoleSlask/Program.cs new file mode 100644 index 0000000..94081eb --- /dev/null +++ b/ConsoleSlask/ConsoleSlask/Program.cs @@ -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); + } + } + +} diff --git a/ConsoleSlask/ConsoleSlask/Properties/AssemblyInfo.cs b/ConsoleSlask/ConsoleSlask/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..aec094f --- /dev/null +++ b/ConsoleSlask/ConsoleSlask/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Exercise1/Exercise1.sln b/Exercise1/Exercise1.sln new file mode 100644 index 0000000..7568f05 --- /dev/null +++ b/Exercise1/Exercise1.sln @@ -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 diff --git a/Exercise1/Exercise1/Account.cs b/Exercise1/Exercise1/Account.cs new file mode 100644 index 0000000..54af56c --- /dev/null +++ b/Exercise1/Exercise1/Account.cs @@ -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; + } + } + } +} \ No newline at end of file diff --git a/Exercise1/Exercise1/Exercise1.csproj b/Exercise1/Exercise1/Exercise1.csproj new file mode 100644 index 0000000..0a51c22 --- /dev/null +++ b/Exercise1/Exercise1/Exercise1.csproj @@ -0,0 +1,66 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {BE0E4F97-1C52-4DD1-9229-10CDDFB6661F} + Exe + Properties + Exercise1 + Exercise1 + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + {A3587AB8-ED1A-4C9F-9981-42863DB18AF9} + StoreData + + + + + \ No newline at end of file diff --git a/Exercise1/Exercise1/Program.cs b/Exercise1/Exercise1/Program.cs new file mode 100644 index 0000000..c36f3dc --- /dev/null +++ b/Exercise1/Exercise1/Program.cs @@ -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(); + } + } +} diff --git a/Exercise1/Exercise1/Properties/AssemblyInfo.cs b/Exercise1/Exercise1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a4671c5 --- /dev/null +++ b/Exercise1/Exercise1/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Exercise1/Exercise1/ShoppingCart.cs b/Exercise1/Exercise1/ShoppingCart.cs new file mode 100644 index 0000000..581dbaf --- /dev/null +++ b/Exercise1/Exercise1/ShoppingCart.cs @@ -0,0 +1,47 @@ +using System.Collections.Generic; +using StoreData; + +namespace Exercise1 +{ + public class ShoppingCart : IShoppingCart + { + private List products = new List(); + + 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 Products + { + get { return products; } + } + } +} \ No newline at end of file diff --git a/Exercise1/Exercise1/ShoppingDemo.cs b/Exercise1/Exercise1/ShoppingDemo.cs new file mode 100644 index 0000000..0ad2c2b --- /dev/null +++ b/Exercise1/Exercise1/ShoppingDemo.cs @@ -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 store; + + /// + /// Constructor + /// + /// + /// + public ShoppingDemo(IShoppingCart cart, IAccount account) + { + PopulateStore(); + this.cart = cart; + this.account = account; + } + + /// + /// Populate the store with a bunch of book titles + /// + private void PopulateStore() + { + store = new List + { + 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} + }; + } + + /// + /// Run the demo application + /// + public void Run() + { + var running = true; + + while (running) + { + PrintMainMenu(); + + var input = Console.ReadLine(); + + if (input == "6") + running = false; + else + MakeChoice(input); + } + } + + /// + /// Make a choice from the main menu + /// + /// + 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; + } + } + + /// + /// Print a list of all products + /// + 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 + /// Shown when it's time to pay + /// + 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(); + } + + /// + /// Clear the shopping cart + /// + private void EmptyShoppingCartDialog() + { + cart.Clear(); + + Console.Clear(); + Console.WriteLine(); + Console.WriteLine(" -- Cleared shopping cart --"); + Console.WriteLine(); + + WaitForInput(); + } + + /// + /// Shown when removing a product + /// + 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(); + } + + /// + /// The dialogue shown when adding a product to the cart + /// + 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(); + } + + /// + /// Shows the main menu + /// + 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: "); + } + + /// + /// Just a method to wait for the user to press enter + /// + private void WaitForInput() + { + Console.WriteLine("Press Enter..."); + Console.ReadLine(); + } + } +} \ No newline at end of file diff --git a/Exercise1/StoreData/IAccount.cs b/Exercise1/StoreData/IAccount.cs new file mode 100644 index 0000000..a4f499a --- /dev/null +++ b/Exercise1/StoreData/IAccount.cs @@ -0,0 +1,22 @@ +namespace StoreData +{ + public interface IAccount + { + /// + /// Check the balance + /// + decimal Balance { get; } + + /// + /// Add money to this account + /// + /// The amount to add + void Add(decimal amount); + + /// + /// Remove money from this account + /// + /// The amount to remove + void Remove(decimal amount); + } +} \ No newline at end of file diff --git a/Exercise1/StoreData/IShoppingCart.cs b/Exercise1/StoreData/IShoppingCart.cs new file mode 100644 index 0000000..6d5413a --- /dev/null +++ b/Exercise1/StoreData/IShoppingCart.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; + +namespace StoreData +{ + public interface IShoppingCart + { + /// + /// This method adds a product to the shopping cart + /// + /// The product to add + void AddProduct(Product p); + + /// + /// Remove product by number + /// + /// The index of the product to remove + void RemoveProductByNumber(int index); + + /// + /// Clears the entire shopping cart + /// + void Clear(); + + /// + /// Calculate the sum of the cost of all products + /// + /// + decimal TotalSum(); + + /// + /// Returns true if cart is empty, otherwise false + /// + bool CartIsEmpty(); + + List Products { get; } + } +} \ No newline at end of file diff --git a/Exercise1/StoreData/Product.cs b/Exercise1/StoreData/Product.cs new file mode 100644 index 0000000..28fe698 --- /dev/null +++ b/Exercise1/StoreData/Product.cs @@ -0,0 +1,8 @@ +namespace StoreData +{ + public class Product + { + public decimal Price { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/Exercise1/StoreData/Properties/AssemblyInfo.cs b/Exercise1/StoreData/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..355ac77 --- /dev/null +++ b/Exercise1/StoreData/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Exercise1/StoreData/StoreData.csproj b/Exercise1/StoreData/StoreData.csproj new file mode 100644 index 0000000..437a716 --- /dev/null +++ b/Exercise1/StoreData/StoreData.csproj @@ -0,0 +1,56 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {A3587AB8-ED1A-4C9F-9981-42863DB18AF9} + Library + Properties + StoreData + StoreData + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Exercise2A/Exercise2A.sln b/Exercise2A/Exercise2A.sln new file mode 100644 index 0000000..0ddcb4e --- /dev/null +++ b/Exercise2A/Exercise2A.sln @@ -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 diff --git a/Exercise2A/Exercise2A/CustomStack.cs b/Exercise2A/Exercise2A/CustomStack.cs new file mode 100644 index 0000000..14a3693 --- /dev/null +++ b/Exercise2A/Exercise2A/CustomStack.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Exercise2A +{ + class CustomStack + { + private List items = new List(); + + 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; + } + } +} diff --git a/Exercise2A/Exercise2A/Exercise2A.csproj b/Exercise2A/Exercise2A/Exercise2A.csproj new file mode 100644 index 0000000..19855ab --- /dev/null +++ b/Exercise2A/Exercise2A/Exercise2A.csproj @@ -0,0 +1,58 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {5C9176E5-EFC6-4B86-857B-C687192BDE9B} + Exe + Properties + Exercise2A + Exercise2A + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Exercise2A/Exercise2A/Program.cs b/Exercise2A/Exercise2A/Program.cs new file mode 100644 index 0000000..9287251 --- /dev/null +++ b/Exercise2A/Exercise2A/Program.cs @@ -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 intStack = new CustomStack(); + CustomStack stringStack = new CustomStack(); + + /* ------ 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(); + } + } +} diff --git a/Exercise2A/Exercise2A/Properties/AssemblyInfo.cs b/Exercise2A/Exercise2A/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..dba8e5b --- /dev/null +++ b/Exercise2A/Exercise2A/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Exercise3/Exercise3.sln b/Exercise3/Exercise3.sln new file mode 100644 index 0000000..8b5a566 --- /dev/null +++ b/Exercise3/Exercise3.sln @@ -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 diff --git a/Exercise3/Exercise3/Exercise3.csproj b/Exercise3/Exercise3/Exercise3.csproj new file mode 100644 index 0000000..c898921 --- /dev/null +++ b/Exercise3/Exercise3/Exercise3.csproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {CBA419E5-E29B-4B4F-A2EA-7721D3701FDA} + Exe + Properties + Exercise3 + Exercise3 + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Exercise3/Exercise3/ListLoader.cs b/Exercise3/Exercise3/ListLoader.cs new file mode 100644 index 0000000..b6e00dd --- /dev/null +++ b/Exercise3/Exercise3/ListLoader.cs @@ -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 LoadListFromFile(string fileName) + { + var list = new List(); + var sr = new StreamReader(fileName); + var line = string.Empty; + + while ((line = sr.ReadLine()) != null) + { + list.Add(line); + } + + sr.Close(); + return list; + } + } +} diff --git a/Exercise3/Exercise3/Program.cs b/Exercise3/Exercise3/Program.cs new file mode 100644 index 0000000..f868c13 --- /dev/null +++ b/Exercise3/Exercise3/Program.cs @@ -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 languages = new List(); + + 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(); + } + } +} diff --git a/Exercise3/Exercise3/Properties/AssemblyInfo.cs b/Exercise3/Exercise3/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..3595066 --- /dev/null +++ b/Exercise3/Exercise3/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Exercise4/Exercise4.sln b/Exercise4/Exercise4.sln new file mode 100644 index 0000000..ebb3008 --- /dev/null +++ b/Exercise4/Exercise4.sln @@ -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 diff --git a/Exercise4/Exercise4/Exercise4.csproj b/Exercise4/Exercise4/Exercise4.csproj new file mode 100644 index 0000000..93fde43 --- /dev/null +++ b/Exercise4/Exercise4/Exercise4.csproj @@ -0,0 +1,59 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {10C24B0F-B14A-4CDD-8393-A657B18CE39F} + Exe + Properties + Exercise4 + Exercise4 + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Exercise4/Exercise4/LanguageData.cs b/Exercise4/Exercise4/LanguageData.cs new file mode 100644 index 0000000..425f6b4 --- /dev/null +++ b/Exercise4/Exercise4/LanguageData.cs @@ -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; + } +} diff --git a/Exercise4/Exercise4/ListLoader.cs b/Exercise4/Exercise4/ListLoader.cs new file mode 100644 index 0000000..3b6541e --- /dev/null +++ b/Exercise4/Exercise4/ListLoader.cs @@ -0,0 +1,31 @@ + +using System.Collections.Generic; +using System.IO; + +namespace Exercise4 +{ + class ListLoader { + + public List LoadListFromFile(string fileName) + { + var list = new List(); + 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; + } + } +} + diff --git a/Exercise4/Exercise4/Program.cs b/Exercise4/Exercise4/Program.cs new file mode 100644 index 0000000..40b2863 --- /dev/null +++ b/Exercise4/Exercise4/Program.cs @@ -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 languages = new List(); + + 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(); + } + } +} diff --git a/Exercise4/Exercise4/Properties/AssemblyInfo.cs b/Exercise4/Exercise4/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d6f18d6 --- /dev/null +++ b/Exercise4/Exercise4/Properties/AssemblyInfo.cs @@ -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")]