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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*.userosscache
*.sln.docstates

# Jetbrains Project Files
.idea/

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down
60 changes: 28 additions & 32 deletions csharp-fundamentals-maps.Main/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,26 @@

namespace csharp_fundamentals_maps.Main
{
public class Core
{

/*
The final fundamental building block of C# is a Dictionary. There is still much to learn about the language,
but this component will allow you to start building lots of more complex pieces of software.

Dictionary<K, V>
K is where you'd put the data type of the key for an item, V is the data type of the value.
If we wanted to map a persons details (their first name, last name, occupation etc.), we could use
a Dictionary using a String key and a String value like so:
Dictionary<string, string>
*/
public class Core
{
/*
The final fundamental building block of C# is a Dictionary. There is still much to learn about the language,
but this component will allow you to start building lots of more complex pieces of software.

Dictionary<K, V>
K is where you'd put the data type of the key for an item, V is the data type of the value.
If we wanted to map a persons details (their first name, last name, occupation etc.), we could use
a Dictionary using a String key and a String value like so:
Dictionary<string, string>
*/

//TODO: Spend some time understanding the method below
/*
- It creates a Map of String, String key value pairs
- It adds some keys with values
- Under the hood, the Dictionary would look like this: { "firstName": "Nathan", "lastName": King, etc. }
- It returns the Dictionary

*/
public Dictionary<string, string> createPerson()
{
Expand All @@ -48,25 +47,20 @@ in the createPerson method

public string getValue(string key)
{


return string.Empty;


return createPerson()[key];
}

//TODO: 2. Modify below method named hasKey that accepts two parameters:
/*
- A Dictionary of string, string key value pairs
- A Dictionary of string, string key value pairs
- string
The method must return a boolean that represents whether the string provided exists as a key
in the provided dictionary
*/
public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
{
return false;

}
public bool hasKey(Dictionary<string, string> dictionary, string isitthere)
{
return dictionary.ContainsKey(isitthere);
}


//TODO: 3. Modify method named getValueOrDefault that accepts two parameters:
Expand All @@ -76,10 +70,9 @@ public bool hasKey(Dictionary<string,string> dictionary, string isitthere)
The method must use the string provided to return the integer contained in the provided HashMap,
or -1 if the string provided is not a key in the HashMap
*/
public int getValueOrDefault(Dictionary<string,int> dictionary, string isitthere)
public int getValueOrDefault(Dictionary<string, int> dictionary, string isitthere)
{
return 0;

return dictionary.GetValueOrDefault(isitthere, -1);
}


Expand All @@ -94,7 +87,7 @@ input output
public List<string> buildSecretPhrase(int[] numbers)
{
List<string> results = new List<string>();

// Do not modify the map
Dictionary<int, string> map = new Dictionary<int, string>();
map.Add(23, "chicken");
Expand All @@ -105,10 +98,13 @@ public List<string> buildSecretPhrase(int[] numbers)
map.Add(96, "nice");
// Write your code below this comment...


foreach (int number in numbers)
{
results.Add(map[number]);
}

// // ...and above this comment
return results;
}
}
}
}
}
44 changes: 9 additions & 35 deletions csharp-fundamentals-maps.Main/Extension.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace csharp_fundamentals_maps.Main
namespace csharp_fundamentals_maps.Main
{
public class Extension
{
Expand All @@ -16,58 +9,41 @@ public Extension()
_planets = new Dictionary<string, float>();
_planets.Add("Jupiter", 5.2f);
_planets.Add("Uranus", 19.2f);
_planets.Add("Pluto", 39f);
// _planets.Add("Pluto", 39f);
_planets.Add("Mercury", 0.39f);
_planets.Add("Saturn", 9.54f);
_planets.Add("Earth", 1f);
_planets.Add("Mars", 1.52f);
_planets.Add("Venus", 0.72f);
_planets.Add("Neptune", 30.06f);
}
//TODO Pluto is unfortunately no longer a planet so please comment out the add line!


public Dictionary<string,int> LettersInName()
{

Dictionary<string, int> result = new Dictionary<string, int>();

//TODO Complete this method to return an Dictionary of <string,int> which contains
// the planet name and the number of letters in its name
// iterate the _planets using a foreach object to load the result dictionary.

foreach (var planet in _planets)
{
result.Add(planet.Key, planet.Key.Length);
}


return result;
}






public Dictionary<string,float> OrderedPlanets()
{
return _planets.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
}
public Dictionary<string, float> OrderedPlanetsByDescending()
{
return _planets.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
return _planets.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
}
//TODO: modify the OrderedPlanetsByDescending so it is not dictionary is not doing an OrderBy but OrderByDescending



//
//TODO using the OrderedPlanets method get the
// furthest from the sun.
// Update the method to return the correct KeyValuePair's Key (the string)!
// Use the ClosestToTheSun as a guide


public string FurthestFromTheSun()
{
return string.Empty;
KeyValuePair<string, float> result = OrderedPlanets().Last();
return result.Key;
}
public string ClosestToTheSun()
{
Expand All @@ -77,7 +53,5 @@ public string ClosestToTheSun()
}

public Dictionary<string,float> Planets { get { return _planets; } }


}
}
Loading