Here, hand this in. It creates a 4x6 array of players...
(I'm gonna venture a guess that this is the only solution you get that has code in it.)
public class Player
{
public int ID { get; set; }
public string Name { get; set; }
public int Height { get; set; }
public int Weight { get; set; }
}
public class Players
{
public double AvgWeight
{
get
{
List<Player> flat = this.Flatten(this.ThePlayers).ToList();
return Math.Round(flat.Average(x=>x.Weight), 1);
}
}
public double AvgHeight
{
get
{
List<Player> flat = this.Flatten(this.ThePlayers).ToList();
return Math.Round(flat.Average(x=>x.Height),1);
}
}
public string Tallest
{
get
{
List<Player> flat = this.Flatten(this.ThePlayers).ToList();
Player player = flat.FirstOrDefault(x=>x.Height == flat.Max(y=>y.Height));
return string.Format("Tallest player: {0} {1}", player.ID, player.Name);
}
}
public string Heaviest
{
get
{
List<Player> flat = this.Flatten(this.ThePlayers).ToList();
Player player = flat.FirstOrDefault(x=>x.Weight == flat.Max(y=>y.Weight));
return string.Format("Tallest player: {0} {1}", player.ID, player.Name);
}
}
public int RandomWeight()
{
return random.Next(63,80);
}
public int RandomHeight()
{
return random.Next(155,180);
}
public IEnumerable<T> Flatten<T>(T[,] map)
{
for (int row = 0; row < map.GetLength(0); row++)
{
for (int col = 0; col < map.GetLength(1); col++)
{
yield return map[row,col];
}
}
}
private Player[,] ThePlayers = null;
Random random = new Random();
public Players()
{
this.ThePlayers = new Player[4,6]
{
{
new Player(){ID=101, Height=RandomHeight(), Name="Adam", Weight=random.Next(63,80)},
new Player(){ID=102, Height=RandomHeight(), Name="Zach", Weight=random.Next(63,80)},
new Player(){ID=103, Height=RandomHeight(), Name="Andy", Weight=random.Next(63,80)},
new Player(){ID=104, Height=RandomHeight(), Name="Bob", Weight=random.Next(63,80)},
new Player(){ID=105, Height=RandomHeight(), Name="Sam", Weight=random.Next(63,80)},
new Player(){ID=106, Height=RandomHeight(), Name="John", Weight=random.Next(63,80)}
},
{
new Player(){ID=107, Height=random.Next(155,180), Name="Pradeep", Weight=random.Next(63,80)},
new Player(){ID=108, Height=random.Next(155,180), Name="Panda", Weight=random.Next(63,80)},
new Player(){ID=109, Height=random.Next(155,180), Name="Deepak", Weight=random.Next(63,80)},
new Player(){ID=110, Height=random.Next(155,180), Name="Reetard", Weight=random.Next(63,80)},
new Player(){ID=111, Height=random.Next(155,180), Name="Dumass", Weight=random.Next(63,80)},
new Player(){ID=112, Height=random.Next(155,180), Name="Skinflute", Weight=random.Next(63,80)}
},
{
new Player(){ID=113, Height=random.Next(155,180), Name="Analpore", Weight=random.Next(63,80)},
new Player(){ID=114, Height=random.Next(155,180), Name="Sumyunguy", Weight=random.Next(63,80)},
new Player(){ID=115, Height=random.Next(155,180), Name="Tittiefreak", Weight=random.Next(63,80)},
new Player(){ID=116, Height=random.Next(155,180), Name="Carpetmuncher", Weight=random.Next(63,80)},
new Player(){ID=117, Height=random.Next(155,180), Name="Dickwad", Weight=random.Next(63,80)},
new Player(){ID=118, Height=random.Next(155,180), Name="Numnuts", Weight=random.Next(63,80)}
},
{
new Player(){ID=119, Height=random.Next(155,180), Name="Asspilot", Weight=random.Next(63,80)},
new Player(){ID=120, Height=random.Next(155,180), Name="Budonkidonks", Weight=random.Next(63,80)},
new Player(){ID=121, Height=random.Next(155,180), Name="Lactator", Weight=random.Next(63,80)},
new Player(){ID=122, Height=random.Next(155,180), Name="Loverope", Weight=random.Next(63,80)},
new Player(){ID=123, Height=random.Next(155,180), Name="Pearlchin", Weight=random.Next(63,80)},
new Player(){ID=124, Height=random.Next(155,180), Name="Bukake", Weight=random.Next(63,80)}
}
};
}
public List<Player> GetUnderWeight(int weight)
{
List<Player> players = this.Flatten(this.ThePlayers).Where(x=>x.Weight < 70).ToList();
return players;
}
}
Usage:
class Program
{
static void Main(string[] args)
{
Players players = new Players();
double avgHeight = players.AvgHeight;
double avgWeight = players.AvgWeight;
string giant = players.Tallest;
string tubbo = players.Heaviest;
List<Player> wimps = players.GetUnderWeight(70);
}
}