Skip to content
Open
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
131 changes: 103 additions & 28 deletions CollectionsMasterConsoleUI/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CollectionsMasterConsoleUI
{
Expand All @@ -13,125 +14,199 @@ static void Main(string[] args)

#region Arrays
//TODO: Create an integer Array of size 50


var numbers= new int[50];
//TODO: Create a method to populate the number array with 50 random numbers that are between 0 and 50


Populater(numbers);
//TODO: Print the first number of the array

//TODO: Print the last number of the array

Console.WriteLine($"first number in array:{numbers[0]}");
//TODO: Print the last number of the array
Console.WriteLine($"last number:{numbers[numbers.Length -1]}");

Console.WriteLine("All Numbers Original");
//UNCOMMENT this method to print out your numbers from arrays or lists
//NumberPrinter();
NumberPrinter(numbers);

Console.WriteLine("-------------------");

//TODO: Reverse the contents of the array and then print the array out to the console.
// Reverse the contents of the array and then print the array out to the console.
//Try for 2 different ways
/* 1) First way, using a custom method => Hint: Array._____();
2) Second way, Create a custom method (scroll to bottom of page to find ⬇⬇⬇)
*/

*/

Console.WriteLine("All Numbers Reversed:");
var numbersReversed = numbers.Reverse();
NumberPrinter(numbersReversed);

Console.WriteLine("---------REVERSE CUSTOM------------");

ReverseArray(numbers);
Console.WriteLine("-------------------");

//TODO: Create a method that will set numbers that are a multiple of 3 to zero then print to the console all numbers
Console.WriteLine("Multiple of three = 0: ");


ThreeKiller(numbers);
NumberPrinter(numbers);
Console.WriteLine("-------------------");

//TODO: Sort the array in order now
/* Hint: Array.____() */
/* Hint: Array.____() */
Console.WriteLine("Sorted numbers:");


Array.Sort(numbers);
NumberPrinter(numbers);


Console.WriteLine("\n************End Arrays*************** \n");
#endregion

#region Lists
Console.WriteLine("************Start Lists**************");



/* Set Up */
//TODO: Create an integer List

var numberList = new List<int>();

//TODO: Print the capacity of the list to the console


Console.WriteLine($"Capacity: {numberList.Capacity}");
//TODO: Populate the List with 50 random numbers between 0 and 50 you will need a method for this


Populater(numberList);
//TODO: Print the new capacity

Console.WriteLine($" New capacity: {numberList.Capacity}");


Console.WriteLine("---------------------");

//TODO: Create a method that prints if a user number is present in the list
//Remember: What if the user types "abc" accident your app should handle that!
Console.WriteLine("What number will you search for in the number list?");


int userNumber;
bool isANumber;

do
{
isANumber = int.TryParse(Console.ReadLine(), out userNumber);
if (!isANumber)
{
Console.WriteLine("Incorrect input.Try again");
}

} while (!isANumber);

NumberChecker(numberList, userNumber);

Console.WriteLine("-------------------");

Console.WriteLine("All Numbers:");
//UNCOMMENT this method to print out your numbers from arrays or lists
//NumberPrinter();
NumberPrinter(numberList);
Console.WriteLine("-------------------");


//TODO: Create a method that will remove all odd numbers from the list then print results
Console.WriteLine("Evens Only!!");


OddKiller(numberList);
NumberPrinter(numberList);

Console.WriteLine("------------------");

//TODO: Sort the list then print results
Console.WriteLine("Sorted Evens!!");

numberList.Sort();
NumberPrinter(numberList);

Console.WriteLine("------------------");

//TODO: Convert the list to an array and store that into a variable

var MyArray = numberList.ToArray();

//TODO: Clear the list
Console.WriteLine($"number list count:{numberList.Count}");


#endregion
}

private static void ThreeKiller(int[] numbers)
{


for (int i = 1; i < numbers.Length; i++)
{
if (numbers[i] % 3 == 0)
{
numbers[i] = 0;

}

}
}

private static void OddKiller(List<int> numberList)
{

for (int i = numberList.Count - 1; i >= 0; i--)
{
if (numberList[i] % 2 != 0)
{
numberList.Remove(numberList[i]);
}
}

}

private static void NumberChecker(List<int> numberList, int searchNumber)
{

if (numberList.Contains(searchNumber))
{
Console.WriteLine($"Yes we have the number you are looking for");

}
else
{
Console.WriteLine("These are not the numbers you are looking for");
}
}

private static void Populater(List<int> numberList)
{
Random rng = new Random();

while(numberList.Count <= 50)
{
var number = rng.Next(0, 50);
numberList.Add(number);
}
NumberPrinter(numberList);
}

private static void Populater(int[] numbers)
{
Random rng = new Random();
for (var i = 0; i < numbers.Length; i++)
{
numbers[i] = rng.Next(0, 50);
}

}

}

private static void ReverseArray(int[] array)
{

var reversedArray = new int[array.Length];

var counter = 0;
for (var i = array.Length - 1; i >=0; i--)
{
reversedArray[counter] = array[i];
}
NumberPrinter(reversedArray);

}

/// <summary>
Expand Down