using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication4
{
class Course
{
private string name;
private int grade;
public Course(string name)
{
this.name = name;
this.grade = -1;
}
public Course(string name, int grade)
{
this.name = name;
this.grade = grade;
}
public string Name
{
get { return this.name; }
set { this.name = value; }
}
public int Grade
{
get { return this.grade; }
set { this.grade = value; }
}
}
class Student
{
string name;
Course[] myCourse;
public Student(string name, Course[] courses)
{
this.name = name;
myCourse = courses;
}
public int CourseGradeSum()
{
int sum = 0;
for (int i = 0; i < myCourse.Length; i++)
{
sum += myCourse[i].Grade;
}
return sum;
}
public bool IsBetterThan(Student s1)
{
if (this.CourseGradeSum() > s1.CourseGradeSum()) return true;
else return false;
}
public static Student WhoIsBest(Student s1, Student s2)
{
if (s1.IsBetterThan(s2)) return s1;
else return s2;
}
public static Student WhoIsBest(Student[] ss)
{
int index = -1;
int maxGradeSum = 0;
for (int i = 0; i < ss.Length; i++)
{
if (ss[i].CourseGradeSum() > maxGradeSum)
{
maxGradeSum = ss[i].CourseGradeSum();
index = i;
}
}
return ss[index];
}
public string GetInfo()
{
return "姓名:" + name + ";总分:" + this.CourseGradeSum().ToString();
}
}
//控制类
class Test
{
static void Main(string[] args)
{
Course[] a = new Course[3];
a[0] = new Course("数据结构", 80);
a[1] = new Course("数据库", 90);
a[2] = new Course("软件工程", 70);
Student John = new Student("John", a);
Course[] b = new Course[3];
b[0] = new Course("数据结构", 70);
b[1] = new Course("数据库", 80);
b[2] = new Course("软件工程", 60);
Student Mike = new Student("Mike", b);
Course[] c = new Course[3];
c[0] = new Course("数据结构", 90);
c[1] = new Course("数据库", 80);
c[2] = new Course("软件工程", 90);
Student Rose = new Student("Rose", c);
Student[] ss = { John, Mike, Rose };
Console.WriteLine("最佳学生:{0}",
Student.WhoIsBest(ss).GetInfo());
}
}
}