class Program
{
static void Main(string[] args)
{
Console.WriteLine("---------------------第一题-----------------------------");
// 1、自己定义抽象类Animal, 抽象出几个抽象方法,
//再定义一个DOG类,去继承抽象类Animal,
//需要重写抽象类中的抽象方法,写出测试案例;
Animal ani = new Dog();
ani.Eat();
Dog dog = new Dog();
dog.Eat();
Console.WriteLine("---------------------第二题-----------------------------");
// 2、创建一个Vehicle类并将它声明为抽象类。
//在Vehicle类中声明一个NoOfWheels方法,使它返回一个字符串值。
//创建两个类Car和Motorbike从Vehicle类继承,并在这两个类中实现NoOfWheels方法。
//在Car类中,应当显示“四轮车”信息;
//而在Motorbike类中,应当显示“双轮车”信息。
//创建另一个带Main方法的类,在该类中创建Car和Motorbike的实例,并在控制台中显示消息
Car car = new Car();
MotoBike moto = new MotoBike();
Console.WriteLine("---------------------第三题-----------------------------");
//3、某学校对教师每月工资的计算公式如下:固定工资 + 课时补贴。
//专家级讲师的的固定工资为25000元,每个课时补贴60元;
//高级讲师的固定工资为18000元,每个课时补贴50元;
//普通讲师的固定工资为12000元,每个课时补贴40元。
//定义教师抽象类,派生不同职称的教师类,编写程序求若干教师的月工资
Teacher zj = new ZhuangjiaTeacher(10);//参数为总课时补贴
Teacher gj = new GaojiTeacher(9);
Teacher pt = new PutongTeacher(8);
Console.ReadKey();
}
}
abstract class Animal
{
public abstract void Eat();
public abstract void Drink();
public abstract void La();
public abstract void Sa();
}
class Car:Vehicle
{
public Car()
{
Console.WriteLine("Car 是:{0}", this.NoOfWheels());
}
public override string NoOfWheels()
{
this.Str = "四轮车";
return Str;
}
}
class Dog:Animal
{
public override void Drink()
{
Console.WriteLine("吃!");
}
public override void Eat()
{
Console.WriteLine("喝!");
}
public override void La()
{
Console.WriteLine("辣!");
}
public override void Sa()
{
Console.WriteLine("撒!");
}
}
class GaojiTeacher:Teacher
{
public GaojiTeacher(int i)
{
this.Gongzi = 18000;
this.Butie = 50 * i;
this.Salary();
}
public override void Salary()
{
Console.WriteLine("高级讲师的固定工资是:{0} 课时补贴是:{1} 总工资是:{2}", this.Gongzi, this.Butie, this.Gongzi + this.Butie);
}
}
class MotoBike:Vehicle
{
public MotoBike() {
Console.WriteLine("MotorBike 是:{0}",this.NoOfWheels());
}
public override string NoOfWheels()
{
this.Str = "两轮车";
return Str;
}
}
class PutongTeacher:Teacher
{
public PutongTeacher(int i)
{
this.Gongzi = 12000;
this.Butie = 40 * i;
this.Salary();
}
public override void Salary()
{
Console.WriteLine("普通讲师的固定工资是:{0} 课时补贴是:{1} 总工资是:{2}", this.Gongzi, this.Butie, this.Gongzi + this.Butie);
}
}
abstract class Teacher
{
private int gongzi;//工资
private int butie;//补贴
public int Gongzi {
set { gongzi = value; }
get { return gongzi; }
}
public int Butie
{
get
{
return butie;
}
set
{
butie = value;
}
}
public abstract void Salary();
}
abstract class Vehicle
{
private string str;
public string Str
{
get { return str; }
set { str = value; }
}
public abstract string NoOfWheels();
}
class ZhuangjiaTeacher:Teacher
{
public ZhuangjiaTeacher(int i) {
this.Gongzi = 25000;
this.Butie = 60*i;
this.Salary();
}
public override void Salary()
{
Console.WriteLine("专家讲师的固定工资是:{0} 课时补贴是:{1} 总工资是:{2}", this.Gongzi,this.Butie,this.Gongzi+this.Butie);
}
}