-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
671 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26730.15 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FerryTerminal", "FerryTerminal\FerryTerminal.csproj", "{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {C22082BB-88AD-4C85-A182-8A5A4F61D3A0} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FerryTerminal | ||
{ | ||
class CargoVehicle : GasVehicle, ICargoCarrier | ||
{ | ||
public bool CargoDoorOpen { get; set; } | ||
|
||
public CargoVehicle(VehicleType vehicleType) : base(vehicleType) | ||
{ | ||
} | ||
|
||
new public static CargoVehicle GetNewInstance(VehicleType vehicleType) | ||
{ | ||
return new CargoVehicle(vehicleType); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FerryTerminal | ||
{ | ||
class ElectricVehicle : Vehicle, IElectricUser | ||
{ | ||
public int BatteryPercent { get; set; } | ||
|
||
public ElectricVehicle(VehicleType vehicleType) : base(vehicleType) | ||
{ | ||
BatteryPercent = RandomPercent(); | ||
} | ||
|
||
public static ElectricVehicle GetNewInstance(VehicleType vehicleType) | ||
{ | ||
return new ElectricVehicle(vehicleType); | ||
} | ||
|
||
public bool NeedsRecharge() | ||
{ | ||
return BatteryPercent <= 10; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FerryTerminal | ||
{ | ||
enum FerryType | ||
{ | ||
Small, | ||
Large, | ||
Eco | ||
} | ||
|
||
class Ferry | ||
{ | ||
public FerryType FerryType { get; private set; } | ||
|
||
int _capacity; | ||
|
||
IList<VehicleType> _acceptedVehicleTypeList; | ||
|
||
List<IVehicle> _vehicleList = new List<IVehicle>(); | ||
|
||
public Ferry(FerryType ferryType, int capacity, IList<VehicleType> acceptedVehicleTypeList) | ||
{ | ||
FerryType = ferryType; | ||
|
||
_capacity = capacity; | ||
|
||
_acceptedVehicleTypeList = acceptedVehicleTypeList; | ||
} | ||
|
||
public bool AcceptVehicle(IVehicle vehicle) | ||
{ | ||
if (_acceptedVehicleTypeList.Contains(vehicle.VehicleType)) | ||
{ | ||
_vehicleList.Add(vehicle); | ||
|
||
if (_vehicleList.Count == _capacity) | ||
{ | ||
// sail away and come back | ||
|
||
_vehicleList.Clear(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FerryTerminal | ||
{ | ||
enum FerryTerminalLocation | ||
{ | ||
Slovenia, | ||
Croatia | ||
} | ||
|
||
class FerryTerminal | ||
{ | ||
float _income = 0; | ||
|
||
FerryTerminalLocation _ferryTerminalLocation; | ||
|
||
IDictionary<VehicleType, float> _vehicleTicketPriceDictionary; | ||
|
||
List<Ferry> _ferryList = new List<Ferry>(); | ||
|
||
Queue<TerminalEmployee> _terminalEmployeeList = new Queue<TerminalEmployee>(); | ||
|
||
public FerryTerminal(FerryTerminalLocation ferryTerminalLocation, IDictionary<VehicleType, float> vehicleTicketPriceDictionary) | ||
{ | ||
_ferryTerminalLocation = ferryTerminalLocation; | ||
|
||
_vehicleTicketPriceDictionary = vehicleTicketPriceDictionary; | ||
|
||
_terminalEmployeeList.Enqueue(new TerminalEmployee(0, 0.1f)); | ||
_terminalEmployeeList.Enqueue(new TerminalEmployee(1, 0.11f)); | ||
|
||
_ferryList.Add(new Ferry(FerryType.Small, 8, new List<VehicleType> { VehicleType.Car, VehicleType.Van })); | ||
_ferryList.Add(new Ferry(FerryType.Large, 6, new List<VehicleType> { VehicleType.Bus, VehicleType.Truck })); | ||
_ferryList.Add(new Ferry(FerryType.Eco, 10, new List<VehicleType> { VehicleType.Electric, VehicleType.Hybrid })); | ||
} | ||
|
||
public void ProcessVehicle(IVehicle vehicle) | ||
{ | ||
Console.WriteLine("Vehicle location: Arrival"); | ||
|
||
if (vehicle is ITicketPayer) | ||
{ | ||
ChargeTicket(vehicle as ITicketPayer); | ||
} | ||
|
||
if (vehicle is IGasUser) | ||
{ | ||
FillUpGas(vehicle as IGasUser); | ||
} | ||
|
||
if (vehicle is IElectricUser) | ||
{ | ||
FillUpBattery(vehicle as IElectricUser); | ||
} | ||
|
||
if (vehicle is ICargoCarrier) | ||
{ | ||
CustomsInspection(vehicle as ICargoCarrier); | ||
} | ||
|
||
LoadVehicleOnFerry(vehicle); | ||
|
||
Console.WriteLine(); | ||
} | ||
|
||
private void ChargeTicket(ITicketPayer ticketPayer) | ||
{ | ||
Console.WriteLine("Charging ticket for " + ticketPayer.GetTicketType()); | ||
|
||
float price = _vehicleTicketPriceDictionary[ticketPayer.GetTicketType()]; | ||
|
||
float amount = ticketPayer.GetMoney(price); | ||
|
||
TerminalEmployee terminalEmployee = _terminalEmployeeList.Dequeue(); | ||
float salary = amount * terminalEmployee.IncomePercent; | ||
terminalEmployee.AddMoney(salary); | ||
amount -= salary; | ||
_terminalEmployeeList.Enqueue(terminalEmployee); | ||
|
||
_income += amount; | ||
|
||
Console.WriteLine("Terminal income is now " + _income); | ||
} | ||
|
||
private void FillUpGas(IGasUser gasUser) | ||
{ | ||
Console.WriteLine("Amount of gas " + gasUser.GasPercent); | ||
|
||
if (gasUser.NeedsRefill()) | ||
{ | ||
gasUser.GasPercent = 100; | ||
|
||
Console.WriteLine("Vehicle location: Gas station"); | ||
} | ||
} | ||
|
||
private void FillUpBattery(IElectricUser electricUser) | ||
{ | ||
Console.WriteLine("Amount of battery " + electricUser.BatteryPercent); | ||
|
||
if (electricUser.NeedsRecharge()) | ||
{ | ||
electricUser.BatteryPercent = 100; | ||
|
||
Console.WriteLine("Vehicle location: Battery recharge station"); | ||
} | ||
} | ||
|
||
private void CustomsInspection(ICargoCarrier cargoCarrier) | ||
{ | ||
Console.WriteLine("Vehicle location: Customs inspection"); | ||
|
||
Console.WriteLine("Cargo doors are open: " + cargoCarrier.CargoDoorOpen); | ||
|
||
cargoCarrier.CargoDoorOpen = true; | ||
|
||
Console.WriteLine("Cargo doors are open: " + cargoCarrier.CargoDoorOpen); | ||
|
||
cargoCarrier.CargoDoorOpen = false; | ||
|
||
Console.WriteLine("Cargo doors are open: " + cargoCarrier.CargoDoorOpen); | ||
} | ||
|
||
private void LoadVehicleOnFerry(IVehicle vehicle) | ||
{ | ||
foreach (Ferry ferry in _ferryList) | ||
{ | ||
if (ferry.AcceptVehicle(vehicle)) | ||
{ | ||
Console.WriteLine("Vehicle location: " + ferry.FerryType + " ferry"); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{48FE9CAA-98AE-49EF-B7DF-60B27EAAD3FE}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>FerryTerminal</RootNamespace> | ||
<AssemblyName>FerryTerminal</AssemblyName> | ||
<TargetFrameworkVersion>v4.6.1</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.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CargoVehicle.cs" /> | ||
<Compile Include="ElectricVehicle.cs" /> | ||
<Compile Include="Ferry.cs" /> | ||
<Compile Include="FerryTerminal.cs" /> | ||
<Compile Include="HybridVehicle.cs" /> | ||
<Compile Include="ICargoCarrier.cs" /> | ||
<Compile Include="IElectricUser.cs" /> | ||
<Compile Include="IGasUser.cs" /> | ||
<Compile Include="ITicketPayer.cs" /> | ||
<Compile Include="IVehicle.cs" /> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="TerminalEmployee.cs" /> | ||
<Compile Include="GasVehicle.cs" /> | ||
<Compile Include="Vehicle.cs" /> | ||
<Compile Include="VehicleFactory.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace FerryTerminal | ||
{ | ||
class GasVehicle : Vehicle, IGasUser | ||
{ | ||
public int GasPercent { get; set; } | ||
|
||
public GasVehicle(VehicleType vehicleType) : base(vehicleType) | ||
{ | ||
GasPercent = RandomPercent(); | ||
} | ||
|
||
public static GasVehicle GetNewInstance(VehicleType vehicleType) | ||
{ | ||
return new GasVehicle(vehicleType); | ||
} | ||
|
||
public bool NeedsRefill() | ||
{ | ||
return GasPercent <= 10; | ||
} | ||
} | ||
} |
Oops, something went wrong.