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
21 changes: 13 additions & 8 deletions csharp-fundamentals-methods.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ 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();
// throw new NotImplementedException();
return $"Hello {name}!";
}



//TODO: 2. Increment a number
/*
Complete this method so that it increases the number given by 1 and returns the result
*/
public int increment(int number)

{
throw new NotImplementedException();
//throw new NotImplementedException();
return number += 1;
}

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

}


//TODO: 4. Construct an array of numbers
Expand All @@ -69,15 +75,14 @@ Create a method named constructNumberArray that accepts two whole numbers named

public int[] constructNumberArray(int lower, int upper)
{

int[] resultArray = { };
int arraySize = upper - lower + 1;
int[] resultArray = Enumerable.Range(lower, arraySize).ToArray();

return resultArray;

}



//TODO: 5. Shout at a dev
/*
Create a method named shout that accepts a string and a whole number.
Expand All @@ -92,7 +97,7 @@ The number of exclamation marks appended must be determined by the number provid

public string shout(string phrase, int number)
{
return $"";
return $"{phrase.ToUpper()}{new string('!', number)}";
}


Expand Down
43 changes: 39 additions & 4 deletions csharp-fundamentals-methods.Main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ public class Extension
"The cake is still baking!" if there are any remaining minutes left,
and "The timer finished ages ago!" if the remaining minutes is a negative number
*/
public double timerStatus(int v)
public string timerStatus(int v)
{
throw new NotImplementedException();
//throw new NotImplementedException();
if (v == 0)
{
return "The cake is ready!";
}

else if (v > 0)
{
return "The cake is still baking!";
}

else
{
return "The timer finished ages ago!";
}

}


Expand All @@ -35,7 +50,16 @@ provided and the prep time per ingredient.

public double estimatePrepTime(string[] strings, int v)
{
throw new NotImplementedException();
//throw new NotImplementedException();
int prepTime = 0;
int ingredientTime = (v > 0) ? v : 2;

for (int i = 0; i < strings.Length; i++)
{
prepTime = strings.Length * ingredientTime;

}
return prepTime;
}


Expand All @@ -51,7 +75,18 @@ public double estimatePrepTime(string[] strings, int v)

public double calculateGramsOfSugar(string[] strings, int v)
{
throw new NotImplementedException();
//throw new NotImplementedException();
int sugarGrams = 0;

for (int i = 0; i < strings.Length; i++)
{
if (strings[i] == "sugar")
{
sugarGrams += v * 100;
}
}

return sugarGrams;
}


Expand Down