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
30 changes: 16 additions & 14 deletions Boolean.CSharp.Main/Core.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Boolean.CSharp.Main.Misc;
Expand Down Expand Up @@ -30,7 +31,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
Expand All @@ -43,10 +44,7 @@ Within the constructor the 'string Make' variable has scope within the construct

//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




return car;
return car;

}

Expand Down Expand Up @@ -92,7 +90,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(4);

return bike;

Expand All @@ -104,11 +102,13 @@ public Unicycle Question4()
//Note the wheelcount has been assigned on the class's property in this case.
//Also note we are instantiating the class below even though there is no constructor on the class?!

//TODO: 3. Add a constructor to the Unicycle class to accept/store the rider name and instantiate with your name below
//TODO: 3. Add a constructor to the Unicycle class to accept/store the rider name and instantiate
//with your name below

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



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

//TODO: 5. Call the FlightDetails method that sets the cancelled message and
//cancel the flight

//write code here
plane.FlightDetails("Your flight is canceled!");
return plane;

}

}
Expand Down
74 changes: 70 additions & 4 deletions Boolean.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@



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

namespace Boolean.CSharp.Main
{
Expand All @@ -12,18 +14,82 @@ 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 value1, float value2)
{
return value1 + value2;
}

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

//TODO: 3. subtract, which accepts two floats and returns a float (first float minus second float)
public float substract(float value1, float value2)
{
return value1 - value2;
}

//TODO: 4. subtract, which accepts a String and a char and returns a string with all instances of the provided char removed
//TODO: 4. subtract, which accepts a String and a char and returns a string with all instances of the provided char removed
public string substract(string string1, char char1)
{
// what method to use to remove the char from the given string input.
// create a new StringBuilder
StringBuilder sb = new StringBuilder();
foreach(char character in string1)
{
if(character != char1)
{
sb.Append(character);
}
}
return sb.ToString();

//throw new NotImplementedException();

//return value1 - value2;
}

//TODO: 5. multiply, which accepts two ints and returns an int (first int multiplied by second int)
public int multiply (int value1, int value2)
{
return value1 * value2;
}

//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"

//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]
//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 strWord, int multiplier) {

StringBuilder sb = new StringBuilder();
for(int i = 0; i < multiplier; i++) {
sb.Append("Hello,");
}
string result = sb.ToString();
//throw new NotImplementedException();
// repeat the string in the given int value input
// remove the comma before returning
return result.Remove(result.Length - 1);
}
//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[] strNumber, int multiplier)
{
// string Array parse to int.
// for loop -> in

int[] result = new int[strNumber.Length];
for(int i = 0; i < strNumber.Length ; i++)
{
//int value2 = int.Parse(value2[i]);
// the index of the new array result[i] is the int index of the Parsed string[] source[i]
// multiplied with the int multiplier
int strNumberToMultiply = int.Parse(strNumber[i]);
result[i] = strNumberToMultiply * multiplier;

}
return result;
}
}
}
15 changes: 8 additions & 7 deletions Boolean.CSharp.Main/Misc/Aeroplane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ public class Aeroplane
private string _journeyDetails;
private bool _flightCancelled;

// empty constructor
public Aeroplane()
{

}
// constructor with two parameters
public bool FlightDetails(string departureAirport, string arrivalAirport)
{
_departureAirport = departureAirport;
Expand All @@ -42,12 +44,11 @@ public int FlightDetails(AeroplanePassengerManifest list)
{
throw new NotImplementedException();
}



public bool IsFlightCancelled => _flightCancelled;






public bool IsFlightCancelled => _flightCancelled;

}

}
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 => _wheelCount ; }
}
}
6 changes: 3 additions & 3 deletions Boolean.CSharp.Main/Misc/Car.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Boolean.CSharp.Main.Misc
{
public class Car
public class Car
{
private string _model;
private string _make;
Expand All @@ -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
11 changes: 8 additions & 3 deletions Boolean.CSharp.Main/Misc/Motorbike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,28 @@ public class Motorbike
private string _make;
private string _model;
private int _cc = 0;





public Motorbike()
{
_cc = 373;
_make = string.Empty;
_model = string.Empty;
}

public Motorbike(string Make, string Model)
{
_make = Make;
_model = Model;
_model = Model;
_cc = 373;

}
public string Make { get; }
public string Model { get; }
public int CC { get; }
// the private int _cc will be the public int CC
public int CC { get => _cc; }

}
}
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;

// constructor that accepts the name of the unicyclist
public Unicycle(string uniCyclist) {
_nameOfUnicyclist = uniCyclist;
}

public string NameOfUnicyclist { get => _nameOfUnicyclist; set => _nameOfUnicyclist = value; }
public int WheelCount { get; set; } = 1;
}
Expand Down
16 changes: 12 additions & 4 deletions Boolean.CSharp.Test/ExtensionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void TestQuestion2()

Assert.AreEqual(3.0, result);
}


[Test]
public void TestQuestion3()
Expand All @@ -49,11 +50,12 @@ public void TestQuestion3()

Extension extension = new Extension();

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

Assert.AreEqual(1.0f, result);
}
}


[Test]
public void TestQuestion4()
{
Expand All @@ -62,10 +64,11 @@ public void TestQuestion4()

Extension extension = new Extension();

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

Assert.IsTrue(result == "the quick brown fox jumps over the lay dog");
}


[Test]
public void TestQuestion5()
Expand All @@ -79,6 +82,8 @@ public void TestQuestion5()

Assert.AreEqual(10, result);
}


[Test]
public void TestQuestion6()
{
Expand All @@ -87,10 +92,12 @@ 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);
}


[Test]
public void TestQuestion7()
{
Expand All @@ -107,6 +114,7 @@ public void TestQuestion7()


}


}
}