diff --git a/Boolean.CSharp.Main/Core.cs b/Boolean.CSharp.Main/Core.cs index e09c536..fb841ff 100644 --- a/Boolean.CSharp.Main/Core.cs +++ b/Boolean.CSharp.Main/Core.cs @@ -30,7 +30,7 @@ public Car(string Make) } */ - Car car = new Car("Volkswagen"); + Car car = new Car("Volkswagen", "Golf"); /* When the car in instantiated, the constructor is passed a string in this case Volkswagen which is a Make of car is passed in. Within the constructor the 'string Make' variable has scope within the constructor and assiged to the _make member now visible to the whole class @@ -92,7 +92,7 @@ public Bicycle Question3() //See there is somewhere to store the number of wheels the bike has //but no constructor to set this //TODO: 3. Add a constructor to the Bicycle class that populates the _wheelCount variable - Bicycle bike = new Bicycle(); + Bicycle bike = new Bicycle(2); return bike; @@ -108,7 +108,7 @@ public Unicycle Question4() //TIP see we already have an internal member for the unicyclist name: _nameOfUnicyclist so you can use this to store the name internally // it is good practice to name internal class variable with an _ at the beginning - Unicycle unicycle = new Unicycle(); + Unicycle unicycle = new Unicycle("Elisabeth"); @@ -132,10 +132,12 @@ What are the parameters and types? */ Aeroplane plane = new Aeroplane(); plane.FlightDetails("LHR", "JFK"); - + //TODO: 5. Call the FlightDetails method that sets the cancelled message and cancel the flight - - //write code here + + //write code here + + plane.FlightDetails("The flight is cancelled"); return plane; } diff --git a/Boolean.CSharp.Main/Extension.cs b/Boolean.CSharp.Main/Extension.cs index 80c1db6..ec34078 100644 --- a/Boolean.CSharp.Main/Extension.cs +++ b/Boolean.CSharp.Main/Extension.cs @@ -7,23 +7,72 @@ namespace Boolean.CSharp.Main { public class Extension - { + { //Implement the following methods: //TODO: 1. add, which accepts two floats and returns a float (both floats added together) + public float add(float a, float b) + { + return a + b; + } + //TODO: 2. add, which accepts two doubles and returns a double (both doubles added together) - //TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float) + public double add(double a, double b) + { + return a + b; + } + + //TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float) + + public float subtract(float a, float b) + { + return a - b; + } - //TODO: 4. subtract, which accepts a String and a char and returns a string with all instances of the provided char removed + //TODO: 4. subtract, which accepts a String and a char and returns a string with all instances of the provided char removed + + public string subtract(string source, char letter) + { + return source.Replace($"{letter}", ""); + } //TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int) + public int multiply(int a, int b) + { + return a * b; + } + //TODO: 6. multiply, which accepts a string and an int, and returns a string containing the provided string as many times as the provided int separated by a comma. E.g. multiply("Hello", 3) -> "Hello,Hello,Hello" - + + public string multiply(string word, int t) + { + string finalWord = word; + + for (int i = 0; i < t-1; i++) + { + finalWord += "," + word; + } + + return finalWord; + } + //TODO: 7. multiply, which accepts an array of Strings that each contain a number, and an int. The method should return an array of ints that contain the value of multiplying each String number by the provided int E.g. multiply(["2", "7", "3"], 3) -> [6, 21, 9] + public int[] multiply(string[] numbers, int a) + { + int[] result = new int[numbers.Length]; + + for (int i = 0; i < numbers.Length; i++) + { + result[i] = Convert.ToInt32(numbers[i]) * a; + } + + return result; + } + } } diff --git a/Boolean.CSharp.Main/Misc/Bicycle.cs b/Boolean.CSharp.Main/Misc/Bicycle.cs index f218c0e..70c219f 100644 --- a/Boolean.CSharp.Main/Misc/Bicycle.cs +++ b/Boolean.CSharp.Main/Misc/Bicycle.cs @@ -10,6 +10,11 @@ public class Bicycle { private int _wheelCount; - public int WheelCount { get; set; } - } + public Bicycle(int wheelCount) + { + _wheelCount = wheelCount; + } + + public int WheelCount { get { return _wheelCount; } } + }; } diff --git a/Boolean.CSharp.Main/Misc/Car.cs b/Boolean.CSharp.Main/Misc/Car.cs index d810f5f..2dde0d8 100644 --- a/Boolean.CSharp.Main/Misc/Car.cs +++ b/Boolean.CSharp.Main/Misc/Car.cs @@ -17,10 +17,10 @@ public Car() _model = string.Empty; _make = string.Empty; } - public Car(string Make) + public Car(string Make, string Model) { _make = Make; - _model = string.Empty; + _model = Model; } public string Make diff --git a/Boolean.CSharp.Main/Misc/Motorbike.cs b/Boolean.CSharp.Main/Misc/Motorbike.cs index 6fcf20b..e47a79b 100644 --- a/Boolean.CSharp.Main/Misc/Motorbike.cs +++ b/Boolean.CSharp.Main/Misc/Motorbike.cs @@ -24,6 +24,7 @@ public Motorbike(string Make, string Model) { _make = Make; _model = Model; + _cc = 373; } public string Make diff --git a/Boolean.CSharp.Main/Misc/Unicycle.cs b/Boolean.CSharp.Main/Misc/Unicycle.cs index 461cb23..1a6bb56 100644 --- a/Boolean.CSharp.Main/Misc/Unicycle.cs +++ b/Boolean.CSharp.Main/Misc/Unicycle.cs @@ -10,6 +10,11 @@ public class Unicycle { private string _nameOfUnicyclist; + public Unicycle(string name) + { + _nameOfUnicyclist = name; + } + public string NameOfUnicyclist { get => _nameOfUnicyclist; set => _nameOfUnicyclist = value; } public int WheelCount { get; set; } = 1; } diff --git a/Boolean.CSharp.Test/ExtensionTests.cs b/Boolean.CSharp.Test/ExtensionTests.cs index f147497..c7d2a52 100644 --- a/Boolean.CSharp.Test/ExtensionTests.cs +++ b/Boolean.CSharp.Test/ExtensionTests.cs @@ -11,8 +11,6 @@ namespace Boolean.CSharp.Test [TestFixture] public class ExtensionTests { - - [Test] public void TestQuestion1() { @@ -28,6 +26,7 @@ public void TestQuestion1() } + [Test] public void TestQuestion2() { @@ -40,7 +39,7 @@ public void TestQuestion2() Assert.AreEqual(3.0, result); } - + [Test] public void TestQuestion3() { @@ -53,7 +52,7 @@ public void TestQuestion3() Assert.AreEqual(1.0f, result); } - + [Test] public void TestQuestion4() { @@ -66,7 +65,7 @@ public void TestQuestion4() Assert.IsTrue(result == "the quick brown fox jumps over the lay dog"); } - + [Test] public void TestQuestion5() { @@ -79,6 +78,7 @@ public void TestQuestion5() Assert.AreEqual(10, result); } + [Test] public void TestQuestion6() { @@ -91,6 +91,7 @@ public void TestQuestion6() Assert.IsTrue("Hello,Hello,Hello" == result); } + [Test] public void TestQuestion7() { @@ -104,9 +105,6 @@ public void TestQuestion7() int[] answer = { 6, 21, 9 }; Assert.IsTrue(result.SequenceEqual(answer)); - - } - } }