⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 10-2.cs

📁 这是学习java基础的好的源代码的学习资料
💻 CS
字号:
//程序10-2
using System;

namespace School
{
	public class Student
	{ 
		protected string studName;
		public Student()
		{}
		public Student(string name)
		{
			studName=name;
			
		}
		public virtual string TheName
		{
			get{return studName;}
		}
		public virtual void PhyEdu()
		{
			Console.WriteLine("  In good health.");
		}
		public virtual void Commonweal()
		{
			Console.WriteLine("  Be of virtue.");
		}
		public virtual void GradePointAverage()
		{
			Console.WriteLine("  The GPA is very high.");
		} 
	
	}
	public class CompStudent:Student
	{ 
		double gpa;
		int Comnweal;
		double phy;
		public CompStudent()
		{}
		public CompStudent(string name, int c, double p,double g):base(name)
		{
			studName=name;
			Comnweal=c;
			phy=p;
			gpa=g;
		}
		public override string TheName
		{
			get{return studName;}
		}
		public override void Commonweal()
		{
			if(Comnweal>=40) Console.WriteLine("  Always helps others.");
		}
		public override void GradePointAverage()
		{
			if(gpa>=3.5)Console.WriteLine("  Excellent GPA: {0} ", gpa);
			
		} 
	
	}
	public class ArtStudent:Student
	{ 
		double gpa;
		int Comnweal;
		double phy;
		public ArtStudent()
		{}
		public ArtStudent(string name, int c, double p,double g):base(name)
		{
			studName=name;
			Comnweal=c;
			phy=p;
			gpa=g;
		}
		public override string TheName
		{
			get{return studName;}
		}
		public override void PhyEdu()
		{
			if(phy>=3.5)	Console.WriteLine("  Good at sports.");
		}
		public override void Commonweal()
		{
			if(Comnweal>=50) Console.WriteLine("  Full of artist's virtue.");
		}
	}
	public class Test
	{
		public static void Evaluate(Student stu)
		{
			Console.WriteLine("The student's name is "+stu.TheName);
			stu.Commonweal();
			stu.PhyEdu();
			stu.GradePointAverage();
		}
		public static void Main()
		{
			Student [] Students=new Student [2];
			Students[0]=new CompStudent("Li",50,3.8,3.7);
			Students[1]=new ArtStudent("Zhang",82,3.5,3.9);
			foreach(Student stud in Students )Evaluate(stud);
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -