In: Computer Science
Create a C# application for Cricket Team that allows you to enter data for player of Cricket Team and saves the data to a file named Players.txt. Create a Player class that contains fields for of participant's first name, last name, age, salary and position (wicketkeeper, bawler, striker, midwicket), and To String() method. The fields of records in the file are separated with semicolon (. Expecting sentinel value for ending the process of writing to file is *. E.g. of a record in the file Players.txt: 180000;bawler
Code
using System;
using static System.Console;
using System.IO;
class CricketTeam
{
class Player
{
private string firstName;
private string lasstName;
private string posiotion;
private int salary;
private int age;
public Player(string fn,string ln,int age,int sal, string
pos)
{
firstName = fn;
lasstName = ln;
this.age = age;
salary = sal;
posiotion = pos;
}
public override string ToString()
{
return firstName + ";" + lasstName + ";" + age + ";" + salary + ";"
+ posiotion;
}
}
static void Main(string[] args)
{
string fName, lName, pos;
int salray, age;
string line = "";
while (true)
{
Console.Write("Enter player's first name or (stop) to quit:
");
fName = Console.ReadLine();
if (fName == "stop")
break;
Console.Write("Enter player's last name: ");
lName = Console.ReadLine();
Console.Write("Enter player's age: ");
Int32.TryParse(Console.ReadLine(), out age);
Console.Write("Enter player's salary: ");
Int32.TryParse(Console.ReadLine(), out salray);
Console.Write("Enter player's position: ");
pos = Console.ReadLine();
Player p1 = new Player(fName, lName, age, salray, pos);
line += p1.ToString() + "\n";
}
using (System.IO.StreamWriter file =new
System.IO.StreamWriter("Players.txt"))
{
file.WriteLine(line);
}
}
}
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.