Skip to content
Browse files

Phase3 - lock/unlock & saloon passcode

  • Loading branch information...
1 parent 4ba0f2b commit 1d4821c788c84e053c3774385309cd74d1f6f5a9 @seanjacob committed Feb 6, 2012
View
3 Cars/Phase3/Automobile.cs
@@ -40,7 +40,8 @@ private void CalculateInfo()
"Manufacturer", Manufacturer,
"Model", Model,
"Wheels", Wheels.ToString(),
- "Gears", Gears.ToString(),
+ "Gears", Gears.ToString(),
+ "EngineCC", EngineCC.ToString(),
"Fuel Level", FuelLevel.ToString()
};
View
21 Cars/Phase4/Automobile.cs
@@ -22,21 +22,24 @@ public class Automobile
public string Info { get; set; }
public bool MOT { get; set; }
public bool SatNav { get; set; }
+ public bool Locked { get; set; }
- public Automobile(bool satnav, string manufacturer, string model)
+ public Automobile(bool satnav, string manufacturer, string model, bool locked)
{
MOT = true;
SatNav = satnav;
Manufacturer = manufacturer;
Model = model;
+ Locked = locked;
}
private void CalculateInfo()
{
string[] infoArr = {
"MOT", MOT.ToString(),
"Sat Nav", SatNav.ToString(),
+ "Locked", Locked.ToString(),
"Manufacturer", Manufacturer,
"Model", Model,
"Wheels", Wheels.ToString(),
@@ -60,6 +63,22 @@ public virtual string GetInfo()
return Info;
}
+ public string Reverse()
+ {
+ return("This vehical is reversing.");
+ }
+
+ public ReturnValue Lock()
+ {
+ Locked = true;
+ return new ReturnValue(true, "Vehical locked.\n");
+ }
+
+ public ReturnValue Unlock()
+ {
+ Locked = false;
+ return new ReturnValue(true, "Vehical unlocked.\n");
+ }
public ReturnValue AddFuel(decimal amount)
{
View
2 Cars/Phase4/Car.cs
@@ -10,7 +10,7 @@ public class Car : Automobile
{
- public Car( bool satnav, string manufacturer, string model) : base(satnav, manufacturer, model)
+ public Car( bool satnav, string manufacturer, string model, bool locked) : base(satnav, manufacturer, model, locked)
{
Wheels = 4;
Gears = 5;
View
2 Cars/Phase4/Hatchback.cs
@@ -9,7 +9,7 @@ namespace Cars.Phase4
public class Hatchback : Car
{
- public Hatchback(bool satnav, string manufacturer, string model) : base( satnav, manufacturer, model)
+ public Hatchback(bool satnav, string manufacturer, string model, bool locked) : base(satnav, manufacturer, model, locked)
{
FuelCapacity = 50;
View
2 Cars/Phase4/Lorry.cs
@@ -9,7 +9,7 @@ namespace Cars.Phase4
public class Lorry : Automobile
{
- public Lorry(bool satnav, string manufacturer, string model) : base(satnav, manufacturer, model)
+ public Lorry(bool satnav, string manufacturer, string model, bool locked) : base(satnav, manufacturer, model, locked)
{
FuelCapacity = 150;
AvgMPG = 10;
View
110 Cars/Phase4/Program4.cs
@@ -1,29 +1,30 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Cars.Phase4
-{
- public class Program4
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Cars.Phase4
+{
+ public class Program4
{
- public Car MyCar { get; set; }
+ 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 Program4()
- {
- MyHatchback = new Hatchback(true, "Citroen", "Saxo");
- MySaloon = new Saloon(true, "Audi", "A3");
- MyLorry = new Lorry(true, "Mercades", "Actros");
-
- CurrentAutomobile = AutomobileType.Hatchback;
+ public AutomobileType CurrentAutomobile { get; set; }
+ public enum AutomobileType
+ {
+ Hatchback,
+ Saloon,
+ Lorry
+ }
+
+ public Program4()
+ {
+ MyHatchback = new Hatchback(true, "Citroen", "Saxo", true);
+ MySaloon = new Saloon(true, "Audi", "A3", true);
+ MyLorry = new Lorry(true, "Mercades", "Actros", true);
+
+ CurrentAutomobile = AutomobileType.Hatchback;
}
public Automobile GetAutomobile()
@@ -36,34 +37,58 @@ public Automobile GetAutomobile()
default : return MyHatchback;
}
- }
-
- public void Run(string command)
+ }
+
+ public void Run(string command)
{
if (command.StartsWith("switch"))
{
switch (CurrentAutomobile)
{
- case AutomobileType.Car : CurrentAutomobile = AutomobileType.Lorry;
+ 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.Car;
- Console.WriteLine("You have switched to a Car\n");
+ case AutomobileType.Lorry: CurrentAutomobile = AutomobileType.Hatchback;
+ Console.WriteLine("You have switched to a Hatchback\n");
break;
}
}
else if (command.StartsWith("get info"))
{
- if (CurrentAutomobile == AutomobileType.Hatchback)
- Console.WriteLine(MyHatchback.GetInfo());
+ Console.WriteLine(GetAutomobile().GetInfo());
+ }
+ 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(MySaloon.GetInfo());
+ {
+ 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)
- Console.WriteLine(MyLorry.GetInfo());
+ {
+ ReturnValue ret = MyLorry.Unlock();
+ if (ret.Success) Console.WriteLine(ret.Message);
+ }
}
else if (command.StartsWith("add fuel")) // Check string
@@ -122,7 +147,14 @@ public void Run(string command)
string commandDrive = Console.ReadLine().ToLower();
if (commandDrive.StartsWith("y"))
{
- Console.WriteLine(GetAutomobile().Drive(mileageAmount));
+ if(GetAutomobile().Locked.Equals(false))
+ {
+ Console.WriteLine(GetAutomobile().Drive(mileageAmount));
+ }
+ else
+ {
+ Console.WriteLine("You need to unlock your " + CurrentAutomobile + ".\n");
+ }
}
else
{
@@ -143,7 +175,7 @@ public void Run(string command)
else
{
Console.WriteLine("Sorry I didn't catch that? \n");
- }
- }
- }
-}
+ }
+ }
+ }
+}
View
32 Cars/Phase4/Saloon.cs
@@ -7,17 +7,37 @@ namespace Cars.Phase4
{
public class Saloon : Car
- {
+ {
- public Saloon( bool satnav, string manufacturer, string model) : base(satnav, manufacturer, model)
+ public string AlarmCode { get; set; }
+
+ public Saloon(bool satnav, string manufacturer, string model, bool locked) : base(satnav, manufacturer, model, locked)
{
- FuelCapacity = 50;
- AvgMPG = 20;
+ FuelCapacity = 70;
+ AvgMPG = 30;
Wheels = 4;
Gears = 5;
- EngineCC = 1400;
- TopSpeed = 120;
+ EngineCC = 1800;
+ TopSpeed = 150;
+ AlarmCode = "abc12345";
+ }
+
+ 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");
+ }
+
+
+ return new ReturnValue(true, "Vehical unlocked.\n");
}
}
View
10 Cars/Program.cs
@@ -18,11 +18,13 @@ public static void Main(string[] args)
Program4 myObject = new Program4();
Console.WriteLine("Welcome to my car app. Please see the available commands below:");
- Console.WriteLine("1. get info - get info of car");
- Console.WriteLine("2. add fuel - add fuel to car");
+ Console.WriteLine("1. get info - get info of vehical");
+ Console.WriteLine("2. add fuel - add fuel to vehical");
Console.WriteLine("3. plan - plan journey");
- Console.WriteLine("4. switch - use a car or lorry\n");
- Console.WriteLine("You are currently in a car\n");
+ Console.WriteLine("4. switch - switch between hatchback, saloon or lorry");
+ Console.WriteLine("5. unlock - unlock vehical");
+ Console.WriteLine("6. lock - lock vehical\n");
+ Console.WriteLine("You are currently in a Hatchback\n");
while (true) // Loop indefinitely
{

0 comments on commit 1d4821c

Please sign in to comment.
Something went wrong with that request. Please try again.