From 71fb61f6dcf77765d5979ffd6e6b5e520fe4c2d0 Mon Sep 17 00:00:00 2001 From: Hugo Meens Date: Sat, 1 Jul 2023 16:44:08 +0200 Subject: [PATCH] exercise finished --- .gitignore | 6 +++ TicketSystem.sln | 16 +++++++ TicketSystem/Order.cs | 57 ++++++++++++++++++++++++ TicketSystem/Program.cs | 16 +++++++ TicketSystem/Properties/AssemblyInfo.cs | 35 +++++++++++++++ TicketSystem/TicketSystem.csproj | 59 +++++++++++++++++++++++++ TicketSystem/Tickets/Adult.cs | 17 +++++++ TicketSystem/Tickets/Child.cs | 17 +++++++ TicketSystem/Tickets/Student.cs | 17 +++++++ TicketSystem/Tickets/Ticket.cs | 15 +++++++ 10 files changed, 255 insertions(+) create mode 100644 .gitignore create mode 100644 TicketSystem.sln create mode 100644 TicketSystem/Order.cs create mode 100644 TicketSystem/Program.cs create mode 100644 TicketSystem/Properties/AssemblyInfo.cs create mode 100644 TicketSystem/TicketSystem.csproj create mode 100644 TicketSystem/Tickets/Adult.cs create mode 100644 TicketSystem/Tickets/Child.cs create mode 100644 TicketSystem/Tickets/Student.cs create mode 100644 TicketSystem/Tickets/Ticket.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4867c4e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ +.idea diff --git a/TicketSystem.sln b/TicketSystem.sln new file mode 100644 index 0000000..2d2ba7d --- /dev/null +++ b/TicketSystem.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TicketSystem", "TicketSystem\TicketSystem.csproj", "{1C26484E-220B-4927-8981-A70201E0232E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1C26484E-220B-4927-8981-A70201E0232E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1C26484E-220B-4927-8981-A70201E0232E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1C26484E-220B-4927-8981-A70201E0232E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1C26484E-220B-4927-8981-A70201E0232E}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/TicketSystem/Order.cs b/TicketSystem/Order.cs new file mode 100644 index 0000000..4fa585d --- /dev/null +++ b/TicketSystem/Order.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using System.Diagnostics; +using TicketSystem.Tickets; + +namespace TicketSystem +{ + public class Order + { + private List tickets; + private int price; + public int Price => price; + + public Order() + { + tickets = new List(); + price = 0; + } + + public void AddTicket(Ticket ticket) + { + tickets.Add(ticket); + price += ticket.price; + } + + public void AddTicket(TicketType type) + { + Ticket t; + switch (type) + { + case TicketType.Child: + t = new Child(); + tickets.Add(t); + price += t.price; + break; + case TicketType.Student: + t = new Student(); + tickets.Add(t); + price += t.price; + break; + case TicketType.Adult: + t = new Adult(); + tickets.Add(t); + price += t.price; + break; + } + } + + public void ApplyReduction() + { + price = 0; + foreach (var ticket in tickets) + { + price += ticket.PriceWithReduction(); + } + } + } +} \ No newline at end of file diff --git a/TicketSystem/Program.cs b/TicketSystem/Program.cs new file mode 100644 index 0000000..11e94ab --- /dev/null +++ b/TicketSystem/Program.cs @@ -0,0 +1,16 @@ +using TicketSystem.Tickets; + +namespace TicketSystem +{ + internal class Program + { + public static void Main(string[] args) + { + Order order = new Order(); + order.AddTicket(TicketType.Child); + order.AddTicket(TicketType.Student); + order.AddTicket(TicketType.Adult); + order.ApplyReduction(); + } + } +} \ No newline at end of file diff --git a/TicketSystem/Properties/AssemblyInfo.cs b/TicketSystem/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..6c6985b --- /dev/null +++ b/TicketSystem/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +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("TicketSystem")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TicketSystem")] +[assembly: AssemblyCopyright("Copyright © 2023")] +[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("1C26484E-220B-4927-8981-A70201E0232E")] + +// 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")] \ No newline at end of file diff --git a/TicketSystem/TicketSystem.csproj b/TicketSystem/TicketSystem.csproj new file mode 100644 index 0000000..dd1b6ab --- /dev/null +++ b/TicketSystem/TicketSystem.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {1C26484E-220B-4927-8981-A70201E0232E} + Exe + Properties + TicketSystem + TicketSystem + v4.7.2 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + diff --git a/TicketSystem/Tickets/Adult.cs b/TicketSystem/Tickets/Adult.cs new file mode 100644 index 0000000..311d415 --- /dev/null +++ b/TicketSystem/Tickets/Adult.cs @@ -0,0 +1,17 @@ +namespace TicketSystem.Tickets +{ + public class Adult: Ticket + { + public int price { get; } + + public Adult() + { + price = 20; + } + + public int PriceWithReduction() + { + return price - price/100*20; + } + } +} \ No newline at end of file diff --git a/TicketSystem/Tickets/Child.cs b/TicketSystem/Tickets/Child.cs new file mode 100644 index 0000000..cdf6893 --- /dev/null +++ b/TicketSystem/Tickets/Child.cs @@ -0,0 +1,17 @@ +namespace TicketSystem.Tickets +{ + public class Child: Ticket + { + public int price { get; } + + public Child() + { + price = 5; + } + + public int PriceWithReduction() + { + return 2; + } + } +} \ No newline at end of file diff --git a/TicketSystem/Tickets/Student.cs b/TicketSystem/Tickets/Student.cs new file mode 100644 index 0000000..32d7c22 --- /dev/null +++ b/TicketSystem/Tickets/Student.cs @@ -0,0 +1,17 @@ +namespace TicketSystem.Tickets +{ + public class Student: Ticket + { + public int price { get; } + + public Student() + { + price = 10; + } + + public int PriceWithReduction() + { + return 10-3; + } + } +} \ No newline at end of file diff --git a/TicketSystem/Tickets/Ticket.cs b/TicketSystem/Tickets/Ticket.cs new file mode 100644 index 0000000..339d42c --- /dev/null +++ b/TicketSystem/Tickets/Ticket.cs @@ -0,0 +1,15 @@ +namespace TicketSystem.Tickets +{ + public enum TicketType + { + Child, + Student, + Adult + } + + public interface Ticket + { + int price { get; } + int PriceWithReduction(); + } +} \ No newline at end of file