Witam potrzebuje pomocy. Chce napisać program w Windows Form, który będzie dodawał zawodników (imię, nazwisko i pesel) oraz punkty (do 10 punktów). Chciałabym też żeby wyświetlał aktualnego zwycięzce oraz średnią punktów. Ale mam problem stanęłam w miejscu. Czy mogłabym prosić o rady i pomoc?
klasa
namespace ListaZawodników
{
public class Zawodnicy
{
private string imie;
private string nazwisko;
private string pesel;
private string punkty;
public string Imie
{
get { return imie; }
set { imie = value; }
}
public string Nazwisko
{
get { return nazwisko; }
set { nazwisko = value; }
}
public string Pesel
{
get { return pesel; }
set
{
if (value.Length == 11)
{
pesel = value;
}
else
{
pesel = "00000000000";
}
}
}
public string Punkty
{
get { return punkty; }
set
{
if (value.Length == 1)
{
punkty = value;
}
else
{
punkty = "0";
}
}
}
public Zawodnicy()
{
Imie= "Janek";
Nazwisko = "Kowalski";
Pesel = "00000000000";
Punkty = "0-10";
}
public Zawodnicy(string imie, string nazwisko, string pesel, string punkty)
{
Imie = imie;
Nazwisko = nazwisko;
Pesel = pesel;
Punkty = punkty;
}
public override string ToString()
{
string output = String.Empty;
output += String.Format("{0}, {1}", Imie, Nazwisko) ;
output += String.Format("({0}{1}{2})", Pesel.Substring(0, 3), Pesel.Substring(3, 3), Pesel.Substring(6, 5));
output += String.Format("{0}", Punkty);
return output;
}
}
}
program
public partial class Form1 : Form
{
private ListaZawodników.Zawodnicy[] listaZawodników = new ListaZawodników.Zawodnicy[1];
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ListaZawodników.Zawodnicy obj = new ListaZawodników.Zawodnicy();
obj.Imie = textBox1.Text;
obj.Nazwisko = textBox2.Text;
obj.Pesel = textBox3.Text;
obj.Punkty = textBox4.Text;
listBox1.Items.Add(obj.ToString());
}
private void button2_Click(object sender, EventArgs e)
{
if (listBox1.SelectedIndex !=-1)
{
int index = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(index);
}
}
private void button3_Click(object sender, EventArgs e)
{
foreach (var item in listBox1.Items)
{
MessageBox.Show(item.ToString());
}
}
}
}