using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//any file handling or IO needs this namespace
using System.IO;
namespace assingment2
{
class Program
{
static void Main(string[] args)
{
int menuChoice = printmenu();
//sentinel
while (menuChoice != -9)
{
switch (menuChoice)
{
case 1:
MenuPart1();
break;
case 2:
MenuPart2();
break;
case 3:
MenuPart3();
break;
default:
break;
}
menuChoice = printmenu();
}
Console.WriteLine("You have Chosen to exit.");
Console.ReadLine();
}//end off main method
private static void MenuPart3()
{
//arrays
int[] noInRange = { 0, 0, 0, 0, 0 };
StreamReader Reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = Reader.ReadLine();
while (lineIn != null)
{
//read into arrays
string[] fields = lineIn.Split(seperator);
int score = Convert.ToInt32(fields[2]);
//process
if (score >= 0 && score <= 399)
{
noInRange[0] = noInRange[0] + 1;
}
else if (score >= 400 && score <= 599)
{
noInRange[1] = noInRange[1] + 1;
}
else if (score >= 600 && score <= 699)
{
noInRange[2] = noInRange[2] + 1;
}
else if (score >= 700 && score <= 999)
{
noInRange[3] = noInRange[3] + 1;
}
else if (score >= 1000)
{
noInRange[4] = noInRange[4] + 1;
}
lineIn = Reader.ReadLine();
}
Console.WriteLine("Range\t\tNumber in this range");
Console.WriteLine("0-399\t\t\t{0}", noInRange[0]);
Console.WriteLine("400-599\t\t\t{0}", noInRange[1]);
Console.WriteLine("600-699\t\t\t{0}", noInRange[2]);
Console.WriteLine("700-999\t\t\t{0}", noInRange[3]);
Console.WriteLine("1000 and over\t\t{0}", noInRange[4]);
Reader.Close();
}//end of menu part 3 method
private static void MenuPart2()
{
Console.WriteLine("Enter the Player Number you wish to search for:");
string playerSearch = Console.ReadLine();
//arrays
StreamReader Reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = Reader.ReadLine();
string found = "";
string score = "";
while (lineIn != null)
{
string[] fields = lineIn.Split(seperator);
//process
if (playerSearch == fields[0])
{
found = fields[1];
score = fields[2];
}
lineIn = Reader.ReadLine();
}
if (found == "")
{
Console.WriteLine("This is not a Valid Code.");
//not found
}
else
{
Console.WriteLine("The details you are looking for are {0} and {1}", found, score);
//found
}
Reader.Close();
}//end of menu part 2 method
private static void MenuPart1()
{
//arrays
StreamReader reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = reader.ReadLine();
Console.WriteLine(" \t ===============\n");
Console.WriteLine("{0,-15}{1,-15}{2,-15}", "PlayerName", "Score", "Citation");
Console.WriteLine("{0,-15}{1,-15}{2,-15}\n", "=========", "=====", "========");
int total = 0;
string topPlayer = "";
int topscore = -1;
while (lineIn != null)
{
string[] fields = lineIn.Split(seperator);
total += Convert.ToInt32(fields[2]);
int score = Convert.ToInt32(fields[2]);
//process
if (score > topscore)
{
topPlayer = fields[1];
topscore = score;
}
string citation = "";
if (score <= 400)
{
citation = "Sluggish Snail";
}
else if (score <= 599)
{
citation = "Ambling Armadeillo";
}
else if (score <= 699)
{
citation = "Bobbing Bobcat";
}
else
{
citation = "TurboCharged Cheetah";
}
Console.WriteLine("{0,-15}{1,-15}{2,-15}\n", fields[1], fields[2], citation);
lineIn = reader.ReadLine();
}
int average = total / 4;
Console.WriteLine("The average Score is {0}", average);
Console.WriteLine("The Top Player is{0}", topPlayer);
reader.Close();
} //end of menu part 1 method
static int printmenu()
{
Console.WriteLine("Main Menu.\n\n-Player Report press 1.\n-Search for a Player press 2.");
Console.WriteLine("-Score analysis press 3.\n-Exit -9.");
int choice = Convert.ToInt32(Console.ReadLine());
return choice;
}//end of menu method
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//any file handling or IO needs this namespace
using System.IO;
namespace assingment2
{
class Program
{
static void Main(string[] args)
{
int menuChoice = printmenu();
//sentinel
while (menuChoice != -9)
{
switch (menuChoice)
{
case 1:
MenuPart1();
break;
case 2:
MenuPart2();
break;
case 3:
MenuPart3();
break;
default:
break;
}
menuChoice = printmenu();
}
Console.WriteLine("You have Chosen to exit.");
Console.ReadLine();
}//end off main method
private static void MenuPart3()
{
//arrays
int[] noInRange = { 0, 0, 0, 0, 0 };
StreamReader Reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = Reader.ReadLine();
while (lineIn != null)
{
//read into arrays
string[] fields = lineIn.Split(seperator);
int score = Convert.ToInt32(fields[2]);
//process
if (score >= 0 && score <= 399)
{
noInRange[0] = noInRange[0] + 1;
}
else if (score >= 400 && score <= 599)
{
noInRange[1] = noInRange[1] + 1;
}
else if (score >= 600 && score <= 699)
{
noInRange[2] = noInRange[2] + 1;
}
else if (score >= 700 && score <= 999)
{
noInRange[3] = noInRange[3] + 1;
}
else if (score >= 1000)
{
noInRange[4] = noInRange[4] + 1;
}
lineIn = Reader.ReadLine();
}
Console.WriteLine("Range\t\tNumber in this range");
Console.WriteLine("0-399\t\t\t{0}", noInRange[0]);
Console.WriteLine("400-599\t\t\t{0}", noInRange[1]);
Console.WriteLine("600-699\t\t\t{0}", noInRange[2]);
Console.WriteLine("700-999\t\t\t{0}", noInRange[3]);
Console.WriteLine("1000 and over\t\t{0}", noInRange[4]);
Reader.Close();
}//end of menu part 3 method
private static void MenuPart2()
{
Console.WriteLine("Enter the Player Number you wish to search for:");
string playerSearch = Console.ReadLine();
//arrays
StreamReader Reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = Reader.ReadLine();
string found = "";
string score = "";
while (lineIn != null)
{
string[] fields = lineIn.Split(seperator);
//process
if (playerSearch == fields[0])
{
found = fields[1];
score = fields[2];
}
lineIn = Reader.ReadLine();
}
if (found == "")
{
Console.WriteLine("This is not a Valid Code.");
//not found
}
else
{
Console.WriteLine("The details you are looking for are {0} and {1}", found, score);
//found
}
Reader.Close();
}//end of menu part 2 method
private static void MenuPart1()
{
//arrays
StreamReader reader = File.OpenText(@"h:\scores.txt");
char[] seperator = { ',' };
string lineIn = reader.ReadLine();
Console.WriteLine(" \t ===============\n");
Console.WriteLine("{0,-15}{1,-15}{2,-15}", "PlayerName", "Score", "Citation");
Console.WriteLine("{0,-15}{1,-15}{2,-15}\n", "=========", "=====", "========");
int total = 0;
string topPlayer = "";
int topscore = -1;
while (lineIn != null)
{
string[] fields = lineIn.Split(seperator);
total += Convert.ToInt32(fields[2]);
int score = Convert.ToInt32(fields[2]);
//process
if (score > topscore)
{
topPlayer = fields[1];
topscore = score;
}
string citation = "";
if (score <= 400)
{
citation = "Sluggish Snail";
}
else if (score <= 599)
{
citation = "Ambling Armadeillo";
}
else if (score <= 699)
{
citation = "Bobbing Bobcat";
}
else
{
citation = "TurboCharged Cheetah";
}
Console.WriteLine("{0,-15}{1,-15}{2,-15}\n", fields[1], fields[2], citation);
lineIn = reader.ReadLine();
}
int average = total / 4;
Console.WriteLine("The average Score is {0}", average);
Console.WriteLine("The Top Player is{0}", topPlayer);
reader.Close();
} //end of menu part 1 method
static int printmenu()
{
Console.WriteLine("Main Menu.\n\n-Player Report press 1.\n-Search for a Player press 2.");
Console.WriteLine("-Score analysis press 3.\n-Exit -9.");
int choice = Convert.ToInt32(Console.ReadLine());
return choice;
}//end of menu method
}
}