From 6e0a2dbd00a907e69ee0102058b1c0a8dae22911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Jakob=20H=C3=A5land?= Date: Wed, 6 Aug 2025 09:26:06 +0200 Subject: [PATCH] Passes all test --- Boolean.CSharp.Main/Core.cs | 11 ++++---- Boolean.CSharp.Main/Extension.cs | 36 ++++++++++++++++++++++++--- Boolean.CSharp.Main/Misc/Bicycle.cs | 7 ++++++ Boolean.CSharp.Main/Misc/Car.cs | 6 +++++ Boolean.CSharp.Main/Misc/Motorbike.cs | 2 +- Boolean.CSharp.Main/Misc/Unicycle.cs | 2 ++ Boolean.CSharp.Test/ExtensionTests.cs | 2 +- 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/Boolean.CSharp.Main/Core.cs b/Boolean.CSharp.Main/Core.cs index e09c536..8839c44 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", "hello"); /* 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("Hans"); @@ -132,9 +132,10 @@ 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 - + + plane.FlightDetails("Flight canceled"); //write code here return plane; diff --git a/Boolean.CSharp.Main/Extension.cs b/Boolean.CSharp.Main/Extension.cs index 80c1db6..1ac3d83 100644 --- a/Boolean.CSharp.Main/Extension.cs +++ b/Boolean.CSharp.Main/Extension.cs @@ -7,23 +7,51 @@ 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 numOne, float numTwo) => numOne + numTwo; //TODO: 2. add, which accepts two doubles and returns a double (both doubles added together) + public double add(double numOne, double numTwo) => numOne + numTwo; //TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float) + public float subtract(float numOne, float numTwo) => numOne - numTwo; //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 word, char letter) + { + return word.Replace(letter.ToString(), ""); + } //TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int) - + public int multiply(int numOne, int numTwo) => numOne * numTwo; //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 num) + { + string repeatedWord = ""; + for (int i=0; i [6, 21, 9] - + public int[] multiply(string[] numbers, int factor) + { + int[] multipliedList = new int[numbers.Length]; + + for (int i=0;i < numbers.Length; i++) + { + int mulitpliedInt = int.Parse(numbers[i]); + mulitpliedInt *= factor; + + multipliedList[i] = mulitpliedInt; + } + return multipliedList; + } } } diff --git a/Boolean.CSharp.Main/Misc/Bicycle.cs b/Boolean.CSharp.Main/Misc/Bicycle.cs index f218c0e..155220a 100644 --- a/Boolean.CSharp.Main/Misc/Bicycle.cs +++ b/Boolean.CSharp.Main/Misc/Bicycle.cs @@ -10,6 +10,13 @@ public class Bicycle { private int _wheelCount; + public Bicycle(int wheelCount) { + WheelCount = wheelCount; + _wheelCount = wheelCount; + } + public int WheelCount { get; set; } } + + } diff --git a/Boolean.CSharp.Main/Misc/Car.cs b/Boolean.CSharp.Main/Misc/Car.cs index d810f5f..eae974a 100644 --- a/Boolean.CSharp.Main/Misc/Car.cs +++ b/Boolean.CSharp.Main/Misc/Car.cs @@ -23,6 +23,12 @@ public Car(string Make) _model = string.Empty; } + public Car(string Make, string Model) + { + _make = Make; + _model = Model; + } + public string Make { get => _make; diff --git a/Boolean.CSharp.Main/Misc/Motorbike.cs b/Boolean.CSharp.Main/Misc/Motorbike.cs index 6fcf20b..2674227 100644 --- a/Boolean.CSharp.Main/Misc/Motorbike.cs +++ b/Boolean.CSharp.Main/Misc/Motorbike.cs @@ -11,7 +11,7 @@ public class Motorbike { private string _make; private string _model; - private int _cc = 0; + private int _cc = 373; public Motorbike() { diff --git a/Boolean.CSharp.Main/Misc/Unicycle.cs b/Boolean.CSharp.Main/Misc/Unicycle.cs index 461cb23..2a919c5 100644 --- a/Boolean.CSharp.Main/Misc/Unicycle.cs +++ b/Boolean.CSharp.Main/Misc/Unicycle.cs @@ -10,6 +10,8 @@ public class Unicycle { private string _nameOfUnicyclist; + public Unicycle(string nameOfUnicyclist) { _nameOfUnicyclist = nameOfUnicyclist; } + 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..d12b03d 100644 --- a/Boolean.CSharp.Test/ExtensionTests.cs +++ b/Boolean.CSharp.Test/ExtensionTests.cs @@ -90,7 +90,7 @@ public void TestQuestion6() string result = extension.multiply(source, 3); Assert.IsTrue("Hello,Hello,Hello" == result); - } + } [Test] public void TestQuestion7() {