diff --git a/Boolean.CSharp.Main/Core.cs b/Boolean.CSharp.Main/Core.cs index e09c536..36650f2 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","Beetle"); /* 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 @@ -132,10 +132,11 @@ 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("Flight is canceled"); return plane; } diff --git a/Boolean.CSharp.Main/Extension.cs b/Boolean.CSharp.Main/Extension.cs index 80c1db6..56c8722 100644 --- a/Boolean.CSharp.Main/Extension.cs +++ b/Boolean.CSharp.Main/Extension.cs @@ -12,18 +12,51 @@ 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 valueOne, float valueTwo) { + return valueOne + valueTwo; + } //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) - - //TODO: 4. subtract, which accepts a String and a char and returns a string with all instances of the provided char removed + public double add(double valueOne, double valueTwo) { + return valueOne + valueTwo; + } + + //TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float) + public float subtract (float valueOne, float valueTwo) { + return valueOne - valueTwo; + } + + //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 s, char charToRemove) + { + s = s.Replace(charToRemove.ToString(), ""); + return s; + } //TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int) + public int multiply (int valueOne, int valueTwo) { return valueOne * valueTwo; } //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 s, int nrOfTimes) { + string returnS =""; + for (int i = 0; i < nrOfTimes; i++) + { + if(returnS.Length == 0) returnS += s; + else returnS += ',' + s; + } + return returnS; + } + //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[] stringArr, int multiplier) + { + int[] intArr = new int[stringArr.Length]; + for (int i = 0; i < stringArr.Length; i++) + { + intArr[i] = int.Parse(stringArr[i]) * multiplier; + } + return intArr; + } } } diff --git a/Boolean.CSharp.Main/Misc/Bicycle.cs b/Boolean.CSharp.Main/Misc/Bicycle.cs index f218c0e..e14285a 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 =2) + { + _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 b50f8f7..cbab40e 100644 --- a/Boolean.CSharp.Main/Misc/Car.cs +++ b/Boolean.CSharp.Main/Misc/Car.cs @@ -22,9 +22,17 @@ public Car(string Make) _make = Make; _model = string.Empty; } + public Car(string Make, string Model) + { + _make = Make; + _model = Model; + } + + //public string Make { get => _make; set => _make = value; } + //public string Model { get => _model; set => _model = value; } - public string Make { get => _make; set => _make = value; } - public string Model { get => _model; set => _model = value; } + public string Make { get { return _make; } } + public string Model { get { return _model; } } } } diff --git a/Boolean.CSharp.Main/Misc/Motorbike.cs b/Boolean.CSharp.Main/Misc/Motorbike.cs index b57180f..93aef45 100644 --- a/Boolean.CSharp.Main/Misc/Motorbike.cs +++ b/Boolean.CSharp.Main/Misc/Motorbike.cs @@ -21,14 +21,15 @@ public Motorbike() _model = string.Empty; } public Motorbike(string Make, string Model) - { + { + _cc = 373; _make = Make; _model = Model; } public string Make { get; } public string Model { get; } - public int CC { get; } + public int CC { get { return _cc; } } } } diff --git a/Boolean.CSharp.Main/Misc/Unicycle.cs b/Boolean.CSharp.Main/Misc/Unicycle.cs index 461cb23..a4190c2 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() + { + _nameOfUnicyclist = "Linus"; + } + public string NameOfUnicyclist { get => _nameOfUnicyclist; set => _nameOfUnicyclist = value; } public int WheelCount { get; set; } = 1; }