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
24 changes: 14 additions & 10 deletions Boolean.CSharp.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Schema;
using Boolean.CSharp.Main.Misc;

namespace Boolean.CSharp.Main
Expand All @@ -15,22 +16,22 @@ 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..



public Car()
{
_model = string.Empty;
_model = Model;
_make = string.Empty;
}
public Car(string Make)
public Car(string _make, string _model)
{
_make = Make;
_model = string.Empty;
_model = Model;
}
*/

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
Expand Down Expand Up @@ -75,7 +76,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 +93,9 @@ 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(200);



return bike;

Expand All @@ -108,7 +111,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("Aleksander");



Expand All @@ -132,9 +135,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("LHR");
//write code here

return plane;
Expand Down
47 changes: 44 additions & 3 deletions Boolean.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@



using System.ComponentModel;
using System.Numerics;
using System.Reflection.Metadata.Ecma335;
using System.Text;

namespace Boolean.CSharp.Main
{
Expand All @@ -12,18 +15,56 @@ 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 x, float y)
{
return x + y;
}

//TODO: 2. add, which accepts two doubles and returns a double (both doubles added together)
public double add(double x, double y)
{
return x + y;
}

//TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float)

public float subtract(float x, float y)
{
return x - y;
}
//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 str, char c)
{
StringBuilder sb = new StringBuilder();
foreach(char ch in str)
{
if (ch != c)
{
sb.Append(ch);
}
}
return sb.ToString();
}
//TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int)
public int multiply(int x, int y) { return x * y; }

//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 str, int frequency)
{
return string.Join(",", Enumerable.Repeat(str, frequency));
}

//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[] array, int num)
{
var numArray = new int[num];
for (int i = 0; i < numArray.Length; i++)
{
int current;
int.TryParse(array[i], out current);
numArray[i] = current * num;
}

return numArray;
}
}
}
7 changes: 6 additions & 1 deletion Boolean.CSharp.Main/Misc/Bicycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; } set { _wheelCount = value; } }
}
}
8 changes: 4 additions & 4 deletions Boolean.CSharp.Main/Misc/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class Car

public Car()
{
_model = string.Empty;
_make = string.Empty;
_model = Model;
_make = Make;
}
public Car(string Make)
public Car(string Make, string Model)
{
_make = Make;
_model = string.Empty;
_model = Model;
}

public string Make { get => _make; set => _make = value; }
Expand Down
16 changes: 8 additions & 8 deletions Boolean.CSharp.Main/Misc/Motorbike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public Motorbike()
_make = string.Empty;
_model = string.Empty;
}
public Motorbike(string Make, string Model)
{
public Motorbike(string Make, string Model, int CC)
{
_make = Make;
_model = Model;

_model = Model;
_cc = CC;
}
public string Make { get; }
public string Model { get; }
public int CC { get; }

public string Make { get { return _make; } set { _make = value; } }
public string Model { get { return _model; } set { _model = value; } }
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 @@ -10,6 +10,11 @@ public class Unicycle
{
private string _nameOfUnicyclist;

public Unicycle(string Unicyclist)
{
_nameOfUnicyclist = Unicyclist;
}

public string NameOfUnicyclist { get => _nameOfUnicyclist; set => _nameOfUnicyclist = value; }
public int WheelCount { get; set; } = 1;
}
Expand Down
4 changes: 2 additions & 2 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 = (float)extension.add(a, b);

Assert.AreEqual(3.0f, result);

Expand Down Expand Up @@ -83,7 +83,7 @@ public void TestQuestion5()
public void TestQuestion6()
{
string source = "Hello";
int dupes = 3;


Extension extension = new Extension();

Expand Down