Program.cs
using System.Collections.Generic;
using static System.Console;
/// <summary>
/// # # # # # # # # # # #
/// # Mark Hesser #
/// # Feb 14, 18 #
/// # Baseball Player #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// # Instructions: #
/// # Create an application named BaseballPlayer that instantiates and displays a BaseballPlayer object.#
/// # The BaseballPlayer class contains properties that hold a player’s name (a string), jersey number #
/// # (an integer), runs scored (an integer), and position (a string). #
/// # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
/// </summary>
namespace BaseballPlayer
{
class Program
{
static void Main(string[] args)
{
Title = "Baseball Players";
Clear();
#region Declarations
var players = new List<Object>();
//Declare players and Add them to the players list.
//Uses the Player Class to assign values to the object.
var p1 = new Player("Steven Brault", 43, 3, "Pitcher");
players.Add(p1);
var p2 = new Player("Francisco Cervelli", 29, 217, "Catcher");
players.Add(p2);
var p3 = new Player("Josh Bell", 55, 93, "1B");
players.Add(p3);
var p4 = new Player("Josh Harrison", 5, 322, "2B");
players.Add(p4);
var p5 = new Player("David Freese", 23, 408, "3B");
players.Add(p5);
var p6 = new Player("Jordy Mercer", 10, 248, "SS");
players.Add(p6);
var p7 = new Player("Christopher Bostick", 44, 6, "LF");
players.Add(p7);
var p8 = new Player("Jordan Luplow", 47, 6, "CF");
players.Add(p8);
var p9 = new Player("Adam Frazier", 26, 76, "RF");
players.Add(p9);
//Uncomment below for an example of what happens when no Data is entered.
//var p10 = new Player();
//players.Add(p10);
//var p11 = new Player("Tom Brady");
//players.Add(p11);
#endregion
WriteLine(" There are " + players.Count + " players in the roaster.\n");
WriteLine(" Player Jersey Runs Position");
foreach (var item in players)
{
WriteLine(item);
}
Quit();
}
/// <summary>
/// Prompts the User to Press any Key to Quit.
/// </summary>
static void Quit()
{
Write("\n Press Any Key to Quit."); //Put message to the user here.
ReadKey(); //Listens for Key
}
}
}
[/code]
Player.cs
[code language=”csharp”] using System;/// <summary>
/// # # # # # # # # # # #
/// # Mark Hesser #
/// # Feb 14, 18 #
/// # Baseball Player #
/// # # # # # # # # # # #
/// </summary>
namespace BaseballPlayer
{
class Player
{
/// <summary>
/// No Argument Constructor Method, replaces the value with default variables.
/// </summary>
public Player() : this("No Data Available", 0, 0, "")
{
}
/// <summary>
/// Player Entry Constructor Method. Requires at least a name.
/// </summary>
/// <param name="name"></param>
/// <param name="jersey"></param>
/// <param name="runs"></param>
/// <param name="position"></param>
public Player(string name, int jersey = 0, int runs = 0, string position = "")
{
Name = name;
Jersey = jersey;
Runs = runs;
//Available Positions that are compared against in the for loop.
//Valid Entrys are either the players position name or the position code.
string[] Code = { "P", "C", "1B", "2B", "3B", "SS", "LF", "CF", "RF" };
string[] validPositions = { "PITCHER", "CATHCER", "FIRST BASE", "SECOND BASE", "THIRD BASE",
"SHORT STOP", "LEFTFIELD", "CENTER FIELD", "RIGHT FIELD" };
string[] formatPosition = { "Pitcher", "Catcher", "First Baseman", "Second Baseman", "Third Baseman",
"Short Stop", "Left Field", "Center Field", "Right Field" };
//Each position is compared against the valid entrys and assign the variable
//whether it’s a code or the position name. If neither are true, Position Error will occur.
for (int i = 0; i < Code.Length; i++)
{
Position = position.ToUpper();
if (Position == Code[i])
{
Position = formatPosition[i];
break; //Once match is found, break the for loop
}
else if (Position == validPositions[i])
{
Position = formatPosition[i];
break; //Once match is found, break the for loop
}
else
Position = "N/A"; //Error results if there is not a match with the valid positions.
}
}
private string name;
public string Name
{
get { return name.ToUpper(); }
set { name = value; }
}
public int Jersey;
public int Runs;
public string Position;
public override string ToString()
{
return String.Format(" {0,-20} | #{1,-5} | {2,3} | {3}",
Name, Jersey, Runs, Position);
}
}
}
[/code]
![](http://sh.hessercan.com/wp-content/uploads/2017/10/File-Format-Exe-507x507-297x300.png)
![](http://sh.hessercan.com/wp-content/uploads/2017/10/File-Format-Zip-507x507-297x300.png)