|
using System;
using System.Collections.ObjectModel;
using System.Windows.Forms;
namespace UniverseReport
{
/// <summary>
/// A collection for the Numbers object
/// </summary>
///
[Serializable()]
internal class NumberCollection:Collection<Number>
{
public NumberCollection()
{
}
/// <summary>
///Get the sum of all numbers in this collection
/// </summary>
/// <returns>sum or -1 if there are no numbers</returns>
public double GetSum()
{
double total=0.0;
foreach (Number number in this)
{
//MessageBox.Show("getting: "+ number.Data.ToString());
total += number.Data;
//MessageBox.Show("Total: " + total.ToString());
}
// MessageBox.Show("Returning: " + Math.Round(total,2).ToString());
return Math.Round(total,2);
}
/// <summary>
///Get the average of all numbers in this collection
/// </summary>
/// <returns>average or -1 if there are no number</returns>
public double GetAverage()
{
if (this.Count > 0)
return GetSum() / this.Count;
else
return -1;
}
/// <summary>
///Get the maximum number in this collection
/// </summary>
/// <returns>maximum or -1 if there are no number</returns>
public double GetMaximum()
{
if (this.Count > 0)
{
double max = this[0].Data;
foreach (Number number in this)
{
if (number.Data > max)
max = number.Data;
}
return max;
}
else
return -1;
}
public int GetCount()
{
return this.Count;
}
/// <summary>
///Get the minimum number in this collection
/// </summary>
/// <returns>minimum or -1 if there are no number</returns>
public double GetMinimum()
{
if (this.Count > 0)
{
double min = this[0].Data;
foreach (Number number in this)
{
if (number.Data < min)
min = number.Data;
}
return min;
}
else
return -1;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Currently pursuing 'Programming Nirvana' (The ineffable ultimate in which one has attained disinterested wisdom and compassion as it relates to programming)
Respected Technologies
1. Confusor (https://confuser.codeplex.com/)
2. Power Threading (http://www.wintellect.com/Resources/visit-the-power-threading-library)
3. EDI Parsers (http://www.rdpcrystal.com)
Acknowledgements:
Microsoft Certified Technologist for WPF and .Net 3.5 (MCTS)
Microsoft Certified Technologist for WCF and .Net 3.5 (MCTS)
Microsoft Certified Application Developer for .Net (MCAD)
Microsoft Certified Systems Engineer (MCSE)
Microsoft Certified Professional (MCP)
Sun Certified Developer for Java 2 Platform (SCD)
Sun Certified Programmer for Java 2 Platform (SCP)
Sun Certified Web Component Developer (SCWCD)
CompTIA A+ Certified Professional
Registered Business School Teacher for Computer Programming and Computer Applications (2004)
(University of the State of New York Education Department)
Graduated from University At Stony Brook