For this task you are asked to create a NumberList class. This class will need to keep track of a list of any number of floating-point values and be able to perform operations on these values. Use a private List< float> field to keep track of the numbers. For more information on List< >, see the Week 7 lecture slides and chapter 8 of the textbook.

The NumberList class will have the following methods:

void Add(float number)
This method adds number to the end of the list. If myList is a NumberList containing {1, 2} calling myList.Add(3) will mean that myList now contains {1, 2, 3}.

List< float> Numbers()
This method returns a list containing all the numbers in the NumberList. As you should be using a private List to keep track of these numbers anyway, this method should just return that List.

float Minimum()
This method returns the lowest number in the list.

float Maximum()
This method returns the highest number in the list.

float Sum()
This method returns the sum of all numbers in the list. If myList is a NumberList containing {1, 2, 3} calling myList.Sum() will return 6.

float Average()
This method returns the average/mean of all numbers in the list. If myList is a NumberList containing {1, 2, 3} calling myList.Sum() will return 2, as the sum of those numbers is 6 and 6 divided by 3 (the number of numbers in the list) is 2.

int Count()
This method returns the number of numbers in the list. If myList is a NumberList containing {1, 2, 3} calling myList.Count() will return 3.

void DeleteBelow(float threshold)
This method removes from the list all numbers that are below threshold. If myList is a NumberList containing {1, 2, 3} calling myList.DeleteBelow(1.5) will remove 1, leaving just {2, 3}.

void DeleteAbove(float threshold)
This method removes from the list all numbers that are above threshold. If myList is a NumberList containing {1, 2, 3} calling myList.DeleteAbove(1.5) will remove 2 and 3, leaving just {1}.

int CountBelow(float threshold)
This method counts how many numbers in the list are below threshold. If myList is a NumberList containing {1, 2, 3} calling myList.CountBelow(2.5) will return 2.

int CountAbove(float threshold)
This method counts how many numbers in the list are above threshold. If myList is a NumberList containing {1, 2, 3} calling myList.CountAbove(2.5) will return 1.

A simple Main() function is provided, although all it performs is a very basic test of functionality. You may want to add your own testing code. The Main() function is not tested by AMS- only the NumberList class is tested.

If you still have difficulties, here are some tips when writing programs for AMS:

Do not write your program directly into the text box. You should copy and paste the sample code into Visual Studio, write your program there, run it and test it to make sure it works, then paste it into AMS. You only get a limited number of attempts at each AMS exercise, so make sure they count.

Sample code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Numbers
{
public class NumberList
{
// Your private List< float> field should go here
// ...

public void Add(float number)
{
// ...
}

public List< float> Numbers()
{
// ...
}

public float Minimum()
{
// ...
}
public float Maximum()
{
// ...
}
public float Sum()
{
// ...
}
public float Average()
{
// ...
}
public int Count()
{
// ...
}
public void DeleteBelow(float threshold)
{
// ...
}
public void DeleteAbove(float threshold)
{
// ...
}
public int CountBelow(float threshold)
{
// ...
}
public int CountAbove(float threshold)
{
// ...
}
}
public class Program
{
private static string ListToString(List< float> numbers)
{
string text = "";
for (int i = 0; i < numbers.Count; i++)
{
if (i > 0) text += ", ";
text += String.Format("{0}", numbers[i]);
}
text += "";
return text;
}
static void Main(string[] args)
{
NumberList myList = new NumberList();
myList.Add(1);
myList.Add(2);
myList.Add(3);
myList.Add(4);
myList.Add(5);

Console.WriteLine("{0} should be 1", myList.Minimum());
Console.WriteLine("{0} should be 5", myList.Maximum());
Console.WriteLine("{0} should be 15", myList.Sum());
Console.WriteLine("{0} should be 3", myList.Average());
Console.WriteLine("{0} should be 5", myList.Count());
Console.WriteLine("{0} should be 2", myList.CountBelow(2.5f));
Console.WriteLine("{0} should be 2", myList.CountAbove(3.5f));

Console.WriteLine("{0} should be 1, 2, 3, 4, 5", ListToString(myList.Numbers()));
myList.DeleteBelow(2.5f);
Console.WriteLine("{0} should be 3, 4, 5", ListToString(myList.Numbers()));

myList.Add(6);
myList.Add(7);

myList.DeleteAbove(4.5f);
Console.WriteLine("{0} should be 3, 4", ListToString(myList.Numbers()));

Console.WriteLine("nPress enter to exit.");
Console.ReadLine();
}
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.