Skip to content
Closed
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: 18 additions & 5 deletions csharp-fundamentals-methods.Main/Core.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand Down Expand Up @@ -27,7 +28,7 @@ logic. See the example below and take some time to break it down and understand
//TODO: 1. Create a method that accepts a name and returns a greeting
public string greet(string name)
{
throw new NotImplementedException();
return $"Hello {name}!";
}

//TODO: 2. Increment a number
Expand All @@ -36,7 +37,7 @@ Complete this method so that it increases the number given by 1 and returns the
*/
public int increment(int number)
{
throw new NotImplementedException();
return number + 1;
}

//TODO: 3. Construct a friendly greeting
Expand All @@ -50,7 +51,7 @@ Complete this method so that it accepts a name as an input and outputs a friendl
*/
public string happilyGreet(string name)
{
throw new NotImplementedException();
return $"Hi, {name} :)";
}

//TODO: 4. Construct an array of numbers
Expand All @@ -67,7 +68,18 @@ Create a method named constructNumberArray that accepts two whole numbers named

public int[] constructNumberArray(int lower, int upper)
{
int[] resultArray = { };
Console.WriteLine($"lower: {lower}, upper: {upper}");
//int[] resultArray = { };
int size = Math.Abs(lower - upper);
int[] resultArray = new int[size+1];

int idx = 0;

for (int i = lower; i <= upper; i++)
{
resultArray[idx] = i;
idx = idx + 1;
}

return resultArray;
}
Expand All @@ -86,7 +98,8 @@ The number of exclamation marks appended must be determined by the number provid

public string shout(string phrase, int number)
{
return $"";
return $"{phrase.ToUpper()}" + String.Concat(Enumerable.Repeat("!", number));
;
}
}
}
27 changes: 24 additions & 3 deletions csharp-fundamentals-methods.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ public class Extension
*/
public string timerStatus(int timeLeftInMin)
{
throw new NotImplementedException();
if (timeLeftInMin == 0)
{
return "The cake is ready!";
}
else if (timeLeftInMin > 0)
{
return "The cake is still baking!";
}
else
{
return "The timer finished ages ago!";
}
}

//TODO: Extension 2: Estimate Prep Time
Expand All @@ -35,7 +46,11 @@ provided and the prep time per ingredient.

public double estimatePrepTime(string[] ingredients, int prepTimePerIngredient)
{
throw new NotImplementedException();
if (prepTimePerIngredient == 0)
{
prepTimePerIngredient = 2;
}
return ingredients.Length * prepTimePerIngredient;
}

//TODO: Extension 3: calculateGramsOfSugar that accepts two parameters 1 an array of ingredients that will always contain 3 ingredients AND 2 the number of layers the cake has. The cake will need 100g of sugar per layer, if that ingredient is present in the provided list of ingredients. The method should return the number of grams of sugar needed to make the cake.
Expand All @@ -49,7 +64,13 @@ public double estimatePrepTime(string[] ingredients, int prepTimePerIngredient)

public double calculateGramsOfSugar(string[] ingredients, int numberOfCakeLayers)
{
throw new NotImplementedException();
Console.WriteLine(string.Join(", ", ingredients));
int sugarNeeded = 0;
if (ingredients.Contains("sugar"))
{
sugarNeeded += 100 * numberOfCakeLayers;
}
return sugarNeeded;
}
}
}
Loading