exercise finished
This commit is contained in:
commit
71fb61f6dc
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
|
.idea
|
16
TicketSystem.sln
Normal file
16
TicketSystem.sln
Normal file
@ -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
|
57
TicketSystem/Order.cs
Normal file
57
TicketSystem/Order.cs
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using TicketSystem.Tickets;
|
||||||
|
|
||||||
|
namespace TicketSystem
|
||||||
|
{
|
||||||
|
public class Order
|
||||||
|
{
|
||||||
|
private List<Ticket> tickets;
|
||||||
|
private int price;
|
||||||
|
public int Price => price;
|
||||||
|
|
||||||
|
public Order()
|
||||||
|
{
|
||||||
|
tickets = new List<Ticket>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
16
TicketSystem/Program.cs
Normal file
16
TicketSystem/Program.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
TicketSystem/Properties/AssemblyInfo.cs
Normal file
35
TicketSystem/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
59
TicketSystem/TicketSystem.csproj
Normal file
59
TicketSystem/TicketSystem.csproj
Normal 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">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{1C26484E-220B-4927-8981-A70201E0232E}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>TicketSystem</RootNamespace>
|
||||||
|
<AssemblyName>TicketSystem</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Order.cs" />
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Tickets\Adult.cs" />
|
||||||
|
<Compile Include="Tickets\Child.cs" />
|
||||||
|
<Compile Include="Tickets\Student.cs" />
|
||||||
|
<Compile Include="Tickets\Ticket.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>
|
17
TicketSystem/Tickets/Adult.cs
Normal file
17
TicketSystem/Tickets/Adult.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
TicketSystem/Tickets/Child.cs
Normal file
17
TicketSystem/Tickets/Child.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace TicketSystem.Tickets
|
||||||
|
{
|
||||||
|
public class Child: Ticket
|
||||||
|
{
|
||||||
|
public int price { get; }
|
||||||
|
|
||||||
|
public Child()
|
||||||
|
{
|
||||||
|
price = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PriceWithReduction()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
TicketSystem/Tickets/Student.cs
Normal file
17
TicketSystem/Tickets/Student.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
15
TicketSystem/Tickets/Ticket.cs
Normal file
15
TicketSystem/Tickets/Ticket.cs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
namespace TicketSystem.Tickets
|
||||||
|
{
|
||||||
|
public enum TicketType
|
||||||
|
{
|
||||||
|
Child,
|
||||||
|
Student,
|
||||||
|
Adult
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Ticket
|
||||||
|
{
|
||||||
|
int price { get; }
|
||||||
|
int PriceWithReduction();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user