Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: seanjacob/seanjacob_Projects
base: 16a6d9a7d3
...
head fork: seanjacob/seanjacob_Projects
compare: 9f89fc7def
  • 4 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
7 Cars/Cars.csproj
@@ -43,6 +43,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Phase5\Automobile.cs" />
+ <Compile Include="Phase5\Car.cs" />
+ <Compile Include="Phase5\Engine.cs" />
+ <Compile Include="Phase5\Hatchback.cs" />
+ <Compile Include="Phase5\Lorry.cs" />
+ <Compile Include="Phase5\Program5.cs" />
+ <Compile Include="Phase5\Saloon.cs" />
<Compile Include="Phase4\Automobile.cs" />
<Compile Include="Phase4\Car.cs" />
<Compile Include="Phase4\Hatchback.cs" />
View
12 Cars/Phase4/Automobile.cs
@@ -5,7 +5,8 @@
namespace Cars.Phase4
{
-
+
+
public class Automobile
{
public decimal FuelLevel { get; set; }
@@ -24,9 +25,9 @@ public class Automobile
public bool MOT { get; set; }
public bool SatNav { get; set; }
public bool Locked { get; set; }
+
-
- public Automobile(bool satnav, string manufacturer, string model, bool locked, string fueltype)
+ public Automobile( bool satnav, string manufacturer, string model, bool locked, string fueltype)
{
MOT = true;
SatNav = satnav;
@@ -72,7 +73,7 @@ public ReturnValue Lock()
return new ReturnValue(true, "Vehical locked.\n");
}
- public ReturnValue Unlock()
+ public virtual ReturnValue Unlock()
{
Locked = false;
return new ReturnValue(true, "Vehical unlocked.\n");
@@ -103,7 +104,7 @@ public ReturnValue CheckFuelAmount(decimal amount)
}
}
- public virtual ReturnValue CheckFuelType(string type)
+ public virtual ReturnValue CheckFuelType(string fueltype)
{
return new ReturnValue(true, "");
}
@@ -113,6 +114,7 @@ public string Drive(decimal mileageAmount)
Mileage += mileageAmount;
FuelLevel -= (mileageAmount / AvgMPG);
Info = "You have driven " + mileageAmount + " miles. Total car mileage " + Mileage + "\n";
+
return(Info);
}
View
6 Cars/Phase4/Program4.cs
@@ -19,10 +19,10 @@ public enum AutomobileType
}
public Program4()
- {
+ {
MyHatchback = new Hatchback(true, "Citroen", "Saxo", true, "petrol");
MySaloon = new Saloon(true, "Audi", "A3", true, "diesel");
- MyLorry = new Lorry(true, "Mercades", "Actros", true, "petrol");
+ MyLorry = new Lorry( true, "Mercades", "Actros", true, "petrol");
CurrentAutomobile = AutomobileType.Hatchback;
}
@@ -107,7 +107,7 @@ public void Run(string command)
if (retAmount.Success)
{
if (CurrentAutomobile == AutomobileType.Saloon)
- {
+ {
Console.WriteLine("What fuel type to add?");
string fuelTypeAdd = Console.ReadLine().ToLower();
ReturnValue retType = GetAutomobile().CheckFuelType(fuelTypeAdd);
View
7 Cars/Phase4/Saloon.cs
@@ -23,6 +23,11 @@ public Saloon(bool satnav, string manufacturer, string model, bool locked, strin
AlarmCode = "abc12345";
}
+ public override ReturnValue Unlock()
+ {
+ return Unlock("");
+ }
+
public ReturnValue Unlock(string code)
{
if (code.Equals(AlarmCode))
@@ -35,7 +40,7 @@ public ReturnValue Unlock(string code)
Locked = true;
return new ReturnValue(false, "Passcode denied. Vehical locked.\n");
}
- }
+ }
public override ReturnValue CheckFuelType(string type)
{
View
143 Cars/Phase5/Automobile.cs
@@ -0,0 +1,143 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+
+ public class Automobile
+ {
+ public decimal FuelLevel { get; set; }
+ public decimal FuelCapacity { get; set; }
+
+ public decimal AvgMPG { get; set; }
+ public int Wheels { get; set; }
+ public int Gears { get; set; }
+ public int TopSpeed { get; set; }
+ public string Manufacturer { get; set; }
+ public string Model { get; set; }
+ public string FuelType { get; set; }
+
+ public string Info { get; set; }
+ public bool MOT { get; set; }
+ public bool SatNav { get; set; }
+ public bool Locked { get; set; }
+
+ public Engine Engine { get; set; } //Association
+
+
+ public Automobile(Engine engine, bool satnav, string manufacturer, string model, bool locked, string fueltype)
+ {
+ MOT = true;
+ SatNav = satnav;
+ Manufacturer = manufacturer;
+ Model = model;
+ Locked = locked;
+ FuelType = fueltype;
+ Engine = engine;
+ }
+
+ private void CalculateInfo()
+ {
+ string[] infoArr = {
+ "MOT", MOT.ToString(),
+ "Sat Nav", SatNav.ToString(),
+ "Locked", Locked.ToString(),
+ "Manufacturer", Manufacturer,
+ "Model", Model,
+ "Wheels", Wheels.ToString(),
+ "Gears", Gears.ToString(),
+ "Fuel Level", FuelLevel.ToString(),
+ "Fuel Type", FuelType.ToString(),
+ "EngineCC", Engine.EngineCC.ToString(),
+ "Mileage", Engine.Mileage.ToString(),
+ "Service Needed", Engine.ServiceNeeded.ToString()
+ };
+
+ for(int i = 0; i < infoArr.Length; i++)
+ {
+ Info = Info + infoArr[i] + ": ";
+ i++;
+ Info = Info + infoArr[i] + "\n";
+ }
+ }
+
+
+ public virtual string GetInfo()
+ {
+ Info = "";
+ CalculateInfo();
+ return Info;
+ }
+
+ public ReturnValue Lock()
+ {
+ Locked = true;
+ return new ReturnValue(true, "Vehical locked.\n");
+ }
+
+ public virtual ReturnValue Unlock()
+ {
+ Locked = false;
+ return new ReturnValue(true, "Vehical unlocked.\n");
+ }
+
+ public virtual string Reverse()
+ {
+ return("This vehical is reversing...\n");
+ }
+
+ public string AddFuel(decimal amount)
+ {
+ FuelLevel += amount;
+ return ("Fuel added. Current capacity is " + FuelLevel + " litres.\n");
+ }
+
+ public ReturnValue CheckFuelAmount(decimal amount)
+ {
+ decimal newLevel = FuelLevel + amount;
+ if (newLevel <= FuelCapacity)
+ {
+ return new ReturnValue(true, "");
+ }
+ else
+ {
+ decimal available = FuelCapacity - FuelLevel;
+ return new ReturnValue(false, "That’s too much you can only add " + available + " litres.\n");
+ }
+ }
+
+ public virtual ReturnValue CheckFuelType(string fueltype)
+ {
+ return new ReturnValue(true, "");
+ }
+
+ public string Drive(decimal mileageAmount)
+ {
+ FuelLevel -= (mileageAmount / AvgMPG);
+
+ string message = Engine.AddMileage(mileageAmount);
+
+ return(message);
+ }
+
+ public ReturnValue Plan(decimal miles)
+ {
+ decimal FuelNeeded = miles / AvgMPG;
+
+ if (FuelLevel >= FuelNeeded)
+ {
+ decimal fuelLeft = FuelLevel - FuelNeeded;
+
+ return new ReturnValue(true, "After " + miles + " miles you will have " + fuelLeft + " litres remaining. Would you like to take this journey Y/N?" );
+ }
+ else
+ {
+ return new ReturnValue(false, "You don't have enough fuel for this journey. \n");
+ }
+ }
+
+ }
+}
View
21 Cars/Phase5/Car.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+ public class Car : Automobile //Inheritance
+ {
+
+
+ public Car(Engine engine, bool satnav, string manufacturer, string model, bool locked, string fueltype) : base(engine, satnav, manufacturer, model, locked, fueltype)
+ {
+ Wheels = 4;
+ Gears = 5;
+ Engine = engine;
+ }
+
+ }
+}
View
44 Cars/Phase5/Engine.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+ public class Engine
+ {
+ public const int SERVICE_INTERVAL = 600;
+
+ public int EngineCC { get; set; }
+ public decimal Mileage { get; set; }
+ public bool ServiceNeeded { get; set; }
+ public decimal ServiceCounter { get; set; }
+
+ public Engine(int enginecc)
+ {
+ EngineCC = enginecc;
+ }
+
+ public string AddMileage(decimal mileageAmount)
+ {
+ Mileage += mileageAmount;
+ ServiceCounter += mileageAmount;
+
+ if (ServiceCounter >= SERVICE_INTERVAL)
+ {
+ ServiceNeeded = true;
+ }
+
+ return "You have driven " + mileageAmount + " miles. Total vehicle mileage " + Mileage + "\n";
+ }
+
+ public string Service()
+ {
+ ServiceCounter = 0;
+ ServiceNeeded = false;
+ return "Your vehicle has been service.\n";
+ }
+
+ }
+}
View
22 Cars/Phase5/Hatchback.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+ public class Hatchback : Car //Inheritance
+ {
+
+ public Hatchback(Engine engine, bool satnav, string manufacturer, string model, bool locked, string fueltype) : base(engine, satnav, manufacturer, model, locked, fueltype)
+ {
+
+ FuelCapacity = 50;
+ AvgMPG = 20;
+ TopSpeed = 120;
+ Engine = engine;
+ }
+
+ }
+}
View
28 Cars/Phase5/Lorry.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+ public class Lorry : Automobile //Inheritance
+ {
+
+ public Lorry(Engine engine, bool satnav, string manufacturer, string model, bool locked, string fueltype) : base(engine, satnav, manufacturer, model, locked, fueltype)
+ {
+ FuelCapacity = 150;
+ AvgMPG = 10;
+ Wheels = 6;
+ Gears = 6;
+ TopSpeed = 120;
+ Engine = engine;
+ }
+
+ public override string Reverse()
+ {
+ return("BEEP! BEEP! this vehical is reversing...\n");
+ }
+
+ }
+}
View
209 Cars/Phase5/Program5.cs
@@ -0,0 +1,209 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+ public class Program5
+ {
+ public Hatchback MyHatchback { get; set; }
+ public Saloon MySaloon { get; set; }
+ public Lorry MyLorry { get; set; }
+ public AutomobileType CurrentAutomobile { get; set; }
+ public enum AutomobileType
+ {
+ Hatchback,
+ Saloon,
+ Lorry
+ }
+
+ public Program5()
+ {
+ Engine myHatchbackEngine = new Engine(1400);
+ MyHatchback = new Hatchback(myHatchbackEngine, true, "Citroen", "Saxo", true, "petrol");
+
+ Engine mySaloonEngine = new Engine(1800);
+ MySaloon = new Saloon(mySaloonEngine, true, "Audi", "A3", true, "diesel");
+
+ Engine myLorryEngine = new Engine(2000);
+ MyLorry = new Lorry(myLorryEngine, true, "Mercades", "Actros", true, "petrol");
+
+ CurrentAutomobile = AutomobileType.Hatchback;
+ }
+
+ public Automobile GetAutomobile()
+ {
+ switch (CurrentAutomobile)
+ {
+ case AutomobileType.Hatchback : return MyHatchback;
+ case AutomobileType.Saloon: return MySaloon;
+ case AutomobileType.Lorry : return MyLorry;
+ default : return MyHatchback;
+ }
+
+ }
+
+ public void Run(string command)
+ {
+
+ if (command.StartsWith("switch"))
+ {
+ switch (CurrentAutomobile)
+ {
+ case AutomobileType.Hatchback : CurrentAutomobile = AutomobileType.Saloon;
+ Console.WriteLine("You have switched to a Saloon\n");
+ break;
+ case AutomobileType.Saloon: CurrentAutomobile = AutomobileType.Lorry;
+ Console.WriteLine("You have switched to a Lorry\n");
+ break;
+ case AutomobileType.Lorry: CurrentAutomobile = AutomobileType.Hatchback;
+ Console.WriteLine("You have switched to a Hatchback\n");
+ break;
+ }
+ }
+
+ else if (command.StartsWith("get info"))
+ {
+ Console.WriteLine(GetAutomobile().GetInfo());
+ }
+
+ else if (command.StartsWith("service"))
+ {
+ Console.WriteLine(GetAutomobile().Engine.Service());
+ }
+
+ else if (command.StartsWith("lock"))
+ {
+ ReturnValue ret = GetAutomobile().Lock();
+ if (ret.Success) Console.WriteLine(ret.Message);
+ }
+
+ else if (command.StartsWith("unlock"))
+ {
+ if (CurrentAutomobile == AutomobileType.Hatchback)
+ {
+ ReturnValue ret = MyHatchback.Unlock();
+ if (ret.Success) Console.WriteLine(ret.Message);
+ }
+ else if (CurrentAutomobile == AutomobileType.Saloon)
+ {
+ Console.WriteLine("Please provide a code."); ;
+ string code = Console.ReadLine().ToLower();
+ ReturnValue ret = MySaloon.Unlock(code);
+ if (ret.Success) Console.WriteLine(ret.Message);
+ }
+
+ else if (CurrentAutomobile == AutomobileType.Lorry)
+ {
+ ReturnValue ret = MyLorry.Unlock();
+ if (ret.Success) Console.WriteLine(ret.Message);
+ }
+ }
+
+ else if (command.StartsWith("add fuel")) // Check string
+ {
+ try
+ {
+
+ while (true)
+ {
+
+ Console.WriteLine("How much fuel?");
+ string commandAmount = Console.ReadLine();
+ decimal fuelAmount = Decimal.Parse(commandAmount);
+ ReturnValue retAmount = GetAutomobile().CheckFuelAmount(fuelAmount);
+
+ if (retAmount.Success)
+ {
+ if (CurrentAutomobile == AutomobileType.Saloon)
+ {
+ Console.WriteLine("What fuel type to add?");
+ string fuelTypeAdd = Console.ReadLine().ToLower();
+ ReturnValue retType = GetAutomobile().CheckFuelType(fuelTypeAdd);
+
+ if (retType.Success)
+ {
+ Console.WriteLine(GetAutomobile().AddFuel(fuelAmount));
+ break;
+ }
+ else
+ {
+ Console.WriteLine(retType.Message);
+ break;
+ }
+ }
+ else
+ {
+ Console.WriteLine(GetAutomobile().AddFuel(fuelAmount));
+ break;
+ }
+ }
+ else
+ {
+ Console.WriteLine(retAmount.Message);
+ break;
+ }
+ }
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("Sorry an error occurred trying to add the fuel. \n");
+ }
+
+ }
+
+ else if (command.StartsWith("drive"))
+ {
+ try
+ {
+ Console.WriteLine("How many miles?");
+
+ string commandAmount = Console.ReadLine();
+ decimal mileageAmount = Decimal.Parse(commandAmount);
+
+ ReturnValue ret = GetAutomobile().Plan(mileageAmount);
+
+ if (ret.Success == true)
+ {
+ Console.WriteLine(ret.Message);
+ string commandDrive = Console.ReadLine().ToLower();
+ if (commandDrive.StartsWith("y"))
+ {
+ if(GetAutomobile().Locked.Equals(false))
+ {
+ Console.WriteLine(GetAutomobile().Drive(mileageAmount));
+ }
+ else
+ {
+ Console.WriteLine("You need to unlock your " + CurrentAutomobile + ".\n");
+ }
+ }
+ else
+ {
+ Console.WriteLine("Ok then. \n");
+ }
+ }
+ else
+ {
+ Console.WriteLine(ret.Message);
+ }
+ }
+ catch (Exception)
+ {
+ Console.WriteLine("Sorry an error occurred trying to add mileage \n");
+ }
+ }
+
+ else if (command.StartsWith("reverse"))
+ {
+ Console.WriteLine(GetAutomobile().Reverse());
+ }
+
+ else
+ {
+ Console.WriteLine("Sorry I didn't catch that? \n");
+ }
+ }
+ }
+}
View
57 Cars/Phase5/Saloon.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase5
+{
+
+ public class Saloon : Car //Inheritance
+ {
+
+ public string AlarmCode { get; set; }
+
+ public Saloon(Engine engine, bool satnav, string manufacturer, string model, bool locked, string fueltype) : base(engine, satnav, manufacturer, model, locked, fueltype)
+ {
+
+ FuelCapacity = 70;
+ AvgMPG = 30;
+ Wheels = 4;
+ Gears = 5;
+ AlarmCode = "abc12345";
+ Engine = engine;
+ }
+
+ public override ReturnValue Unlock()
+ {
+ return Unlock("");
+ }
+
+ public ReturnValue Unlock(string code)
+ {
+ if (code.Equals(AlarmCode))
+ {
+ Locked = false;
+ return new ReturnValue(true, "Passcode allowed. Vehical unlocked.\n");
+ }
+ else
+ {
+ Locked = true;
+ return new ReturnValue(false, "Passcode denied. Vehical locked.\n");
+ }
+ }
+
+ public override ReturnValue CheckFuelType(string type)
+ {
+ if (type.Equals(FuelType))
+ {
+ return new ReturnValue(true, "");
+ }
+ else
+ {
+ return new ReturnValue(false, "You're trying to add the wrong fuel type.\n");
+ }
+ }
+
+ }
+}
View
18 Cars/Program.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using Cars.Phase4;
+using Cars.Phase5;
namespace Cars
{
@@ -14,17 +14,19 @@ public static void Main(string[] args)
//RunProgram1();
//Program2 myObject = new Program2();
//Program3 myObject = new Program3();
+ //Program4 myObject = new Program4();
- Program4 myObject = new Program4();
+ Program5 myObject = new Program5();
Console.WriteLine("Welcome to my car app. Please see the available commands below:");
- Console.WriteLine("1. get info - get info of vehical");
- Console.WriteLine("2. add fuel - add fuel to vehical");
- Console.WriteLine("3. drive - drive vehical");
- Console.WriteLine("4. reverse - reverse vehical");
+ Console.WriteLine("1. get info - get info of vehicle");
+ Console.WriteLine("2. add fuel - add fuel to vehicle");
+ Console.WriteLine("3. drive - drive vehicle");
+ Console.WriteLine("4. reverse - reverse vehicle");
Console.WriteLine("5. switch - switch between hatchback, saloon or lorry");
- Console.WriteLine("6. unlock - unlock vehical");
- Console.WriteLine("7. lock - lock vehical\n");
+ Console.WriteLine("6. unlock - unlock vehicle");
+ Console.WriteLine("7. lock - lock vehicle");
+ Console.WriteLine("8. service - service vehicle\n");
Console.WriteLine("You are currently in a Hatchback\n");
while (true) // Loop indefinitely

No commit comments for this range

Something went wrong with that request. Please try again.