学生用とマーク用のリストがあります。入力したIDに応じて生徒のマークを追加し、レコードを表示したいと思います。正しく実装していません。誰かがそれを正しく行う方法を教えてもらえますか?これは私が達成しようとしている出力です:1)学生を追加します2)マークを追加します:ユーザーはIDを入力するように求められ、IDが存在する場合は、そのIDに従ってマークが保存されます。3)マークを表示:学生IDと彼のマークを表示
class Student
{
public Student(string name, string surname, string dob, string address)
{
this.Name = name;
this.Surname = surname;
this.DOB = dob;
this.Address = address;
}
public List<Marks> studentId = new List<Marks>();
public List<Marks> Mathematics = new List<Marks>();
public List<Marks> English = new List<Marks>();
public List<Marks> Maltese = new List<Marks>();
public List<Marks> ReligiousStudies = new List<Marks>();
public List<Marks> SocialStudies = new List<Marks>();
public string Name { get; set; }
public string Surname { get; set; }
public string DOB { get; set; }
public string Addr { get; set; }
public string Id { get; set; }
public Student(string s)
{
string[] splitted = s.Split(',');
name = splitted[0];
surname = splitted[1];
dob = splitted[2];
address = splitted[3];
id = splitted[4];
}
public void AddMarks(string id, int hyexam, int anexam)
{
if (Id.Equals(id))
{
studentId.Add(new Marks(id));
Mathematics.Add(new Marks(hyexam, anexam));
English.Add(new Marks(hyexam, anexam));
Maltese.Add(new Marks(hyexam, anexam));
ReligiousStudies.Add(new Marks(hyexam, anexam));
SocialStudies.Add(new Marks(hyexam, anexam));
}
else
{
Console.WriteLine("id not found");
}
}
public void StudMarks()
{
foreach (Marks mrk in studentId)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in Mathematics)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in English)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in Maltese)
{
Console.WriteLine(mrk);
}
foreach (Marks mrk in ReligiousStudies)
{
Console.WriteLine(mrk);
}
}
}
}
public class ClassYear
{
private const string filestud = "C:\\Users\\Maria\\Desktop\\Students\\stud.txt";
public string Year { get; set; }
public List<Student> mystudent=new List <Student> ();
public List<Student> MyStud
{
get { return mystudent; }
}
public void Addstudent(string name,string surname,string dob, string addr)
{
mystudent.Add(new Student(name,surname,dob,addr));
}
private void LoadFromFile()
{
try
{
string s;
StreamReader myFile = File.OpenText(filestud);
while ((s = myFile.ReadLine()) != null)
{
Student st = new Student(s);
mystudent.Add(st);
}
myFile.Close();
}
catch (Exception e)
{
Console.WriteLine("There was a file handling problem");
}
}
private void DumpToFile()
{
try
{
StreamWriter myFile = File.CreateText(filestud);
foreach (Student s in mystudent)
{
myFile.WriteLine(s.ToString());
}
myFile.Close();
}
catch (Exception e)
{
Console.WriteLine("There was a file handling problem");
}
}
private int SearchItem(int search)
{
int found = -1;
if (mystudent != null)
{
foreach (Student st in mystudent)
{
found++;
if (Student.Equals(search,st)) {
break;
}
}
}
return found;
}
private void Delete(int index)
{
SearchItem(index);
mystudent.RemoveAt(index);
foreach (Student st in mystudent) {
Console.WriteLine(st);
}
}
private void EditItem(int index)
{
Student stud = new Student();
SearchItem(index);
mystudent[index] = stud;
Console.WriteLine("current record is" + index);
Console.WriteLine("enter new record:");
stud.Name = Console.ReadLine();
stud.Surname = Console.ReadLine();
stud.Addr = Console.ReadLine();
stud.Id = Console.ReadLine();
foreach (Student st in mystudent)
{
Console.WriteLine(st);
}
}
private void ViewStudents()
{
foreach (Student st in mystudent)
{
Console.WriteLine(st);
}
}
}
}
public class Marks
{
public int HYEXAM { get; private set; }
public int ANEXAM { get; private set; }
public string Id { get; private set; }
public Marks(int hyexam, int anexam)
{
this.HYEXAM = hyexam;
this.ANEXAM = anexam;
}
public Marks(string id)
{
this.Id = id;
}
public double OverallExam()
{
return (0.4 * HEYXAM) + (0.6 * ANEXAM);
}
}
}