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
16 changes: 9 additions & 7 deletions Boolean.CSharp.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public Car()
_model = string.Empty;
_make = string.Empty;
}
public Car(string Make)
public Car(string Make, string )
{
_make = Make;
_model = string.Empty;
}
*/

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 @@ -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(5);

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("Gustav");



Expand All @@ -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("Flight is cancelled!");

return plane;
}
Expand Down
60 changes: 57 additions & 3 deletions Boolean.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


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

namespace Boolean.CSharp.Main
{
Expand All @@ -12,18 +13,71 @@ 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 number1, float number2)
{
return number1 + number2;
}

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

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

public float subtract(float number1, float number2)
{
return number1 - number2;
}
//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 string1, char char1)
{
StringBuilder stringbuilder = new StringBuilder();

foreach (char c in string1)
{
if (c != char1)
{
stringbuilder.Append(c);
}
}
return stringbuilder.ToString();
}
//TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int)

public int multiply(int number1, int number2)
{
return number1 * number2;
}
//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 string1, int number1)
{
StringBuilder stringbuilder = new StringBuilder();

for (int i= 0; i < number1; i++)
{
stringbuilder.Append(string1);

if (i < number1 - 1)
{
stringbuilder.Append(",");
}

}
return stringbuilder.ToString();
}

//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[] stringNumbers, int multiplier)
{
int[] resultArray = new int[stringNumbers.Length];

for (int i= 0;i < stringNumbers.Length; i++)
{
int numberToMutiply = int.Parse(stringNumbers[i]);
resultArray[i] = numberToMutiply * multiplier;
}
return resultArray;
}

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

public int WheelCount { get; set; }
public int WheelCount
{
get { return _wheelCount; }
set { _wheelCount = value; }
}
public Bicycle(int wheelCoult)
{
WheelCount = wheelCoult;
}
}
}
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 { get => _make; set => _make = value; }
Expand Down
7 changes: 4 additions & 3 deletions Boolean.CSharp.Main/Misc/Motorbike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Motorbike
{
private string _make;
private string _model;
private int _cc = 0;
private int _cc = 373;


public Motorbike()
Expand All @@ -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; } }

}
}
6 changes: 6 additions & 0 deletions Boolean.CSharp.Main/Misc/Unicycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@ public class Unicycle

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

public Unicycle(string nameOfUnicyclist)
{
NameOfUnicyclist = nameOfUnicyclist;
}

}
}