Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions Boolean.CSharp.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Core
{
public Car Question1()
{

/*
Examine the code in the Car class. There are 2 constructor methods, identified because they
have the same name as the class which in this case is Car..
Expand All @@ -29,24 +29,24 @@ public Car(string Make)
_model = string.Empty;
}
*/
Car car = new Car("Volkswagen");


/* 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
You can pass multiple variables in by placing a comma after the first, then the next variable
e.g. In the Constructor signature: public Car(string Make, string Model)
e.g. Instantiating: Car car = new Car("Volkswagen", "Beetle");
*/

//TODO: 1. Change car instantiation code above, pass in the make AND model.

//TIP if you click on the Car class name above, right click and then select 'Go to Definition' it'll take you straight to the code


Car car = new Car("Volkswagen", "Beetle");


return car;
return car;

}

Expand Down Expand Up @@ -75,7 +75,7 @@ Having to 2 constructors is an example of Overloading.

*/
//TODO 2. Ensure both constructors on the Motorbike class set the cc of the Motorcycle to 373.
Motorbike myMotorbike = new Motorbike("KTM", "Duke");
Motorbike myMotorbike = new Motorbike("KTM", "Duke", 373);

if(myMotorbike.CC > 0)
{
Expand All @@ -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;

Expand All @@ -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("Tein Schoemaker");



Expand All @@ -132,11 +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

//write code here

plane.FlightDetails("");
return plane;
}

Expand Down
48 changes: 47 additions & 1 deletion Boolean.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,64 @@ 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)
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
public string Subtract(string _string, char _char)
{
return _string.Replace(_char.ToString(), "");
}

//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 a, int b)
{
string result= "";

for (int i = 0; i < b; i++)
{
result += a;

if (i < b - 1)
{
result += ",";
}
}

return result;
}

//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[] a, int b)
{

List<int> result = new List<int>();
foreach (string num in a)
{
result.Add(int.Parse(num) * b);
}
return result.ToArray();
}

}
}
6 changes: 5 additions & 1 deletion Boolean.CSharp.Main/Misc/Bicycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ namespace Boolean.CSharp.Main.Misc
{
public class Bicycle
{
private int _wheelCount;

public int WheelCount { get; set; }

public Bicycle(int wheelCount)
{
WheelCount = wheelCount;
}
}
}
4 changes: 2 additions & 2 deletions Boolean.CSharp.Main/Misc/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Boolean.CSharp.Main/Misc/Motorbike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public Motorbike()
_model = string.Empty;
}

public Motorbike(string Make, string Model)
public Motorbike(string Make, string Model, int CC)
{
_make = Make;
_model = Model;
_cc = CC;
}

public string Make
Expand All @@ -37,6 +38,7 @@ public string Model
public int CC
{
get { return _cc; }
set { _cc = value; }
}
}
}
5 changes: 5 additions & 0 deletions Boolean.CSharp.Main/Misc/Unicycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ public class Unicycle

public string NameOfUnicyclist { get => _nameOfUnicyclist; set => _nameOfUnicyclist = value; }
public int WheelCount { get; set; } = 1;

public Unicycle(string nameOfUnicyclist)
{
_nameOfUnicyclist = nameOfUnicyclist;
}
}
}
14 changes: 7 additions & 7 deletions Boolean.CSharp.Test/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void TestQuestion1()

Extension extension = new Extension();

float result = extension.add(a, b);
float result = extension.Add(a, b);

Assert.AreEqual(3.0f, result);

Expand All @@ -36,7 +36,7 @@ public void TestQuestion2()

Extension extension = new Extension();

double result = extension.add(a, b);
double result = extension.Add(a, b);

Assert.AreEqual(3.0, result);
}
Expand All @@ -49,7 +49,7 @@ public void TestQuestion3()

Extension extension = new Extension();

float result = extension.subtract(a, b);
float result = extension.Subtract(a, b);

Assert.AreEqual(1.0f, result);
}
Expand All @@ -62,7 +62,7 @@ public void TestQuestion4()

Extension extension = new Extension();

string result = extension.subtract(source, z);
string result = extension.Subtract(source, z);

Assert.IsTrue(result == "the quick brown fox jumps over the lay dog");
}
Expand All @@ -75,7 +75,7 @@ public void TestQuestion5()

Extension extension = new Extension();

int result = extension.multiply(a, b);
int result = extension.Multiply(a, b);

Assert.AreEqual(10, result);
}
Expand All @@ -87,7 +87,7 @@ public void TestQuestion6()

Extension extension = new Extension();

string result = extension.multiply(source, 3);
string result = extension.Multiply(source, 3);

Assert.IsTrue("Hello,Hello,Hello" == result);
}
Expand All @@ -99,7 +99,7 @@ public void TestQuestion7()
int multiplier = 3;

Extension extension = new Extension();
var result = extension.multiply(source, multiplier);
var result = extension.Multiply(source, multiplier);

int[] answer = { 6, 21, 9 };

Expand Down
Loading