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、創(chuàng)建一個Vehicle類并將它聲明為抽象類浴鸿。
//在Vehicle類中聲明一個NoOfWheels方法,使它返回一個字符串值弦追。
//創(chuàng)建兩個類Car和Motorbike從Vehicle類繼承岳链,并在這兩個類中實現(xiàn)NoOfWheels方法。
//在Car類中劲件,應(yīng)當(dāng)顯示“四輪車”信息掸哑;
//而在Motorbike類中约急,應(yīng)當(dāng)顯示“雙輪車”信息。
//創(chuàng)建另一個帶Main方法的類苗分,在該類中創(chuàng)建Car和Motorbike的實例厌蔽,并在控制臺中顯示消息
Car car = new Car();
MotoBike moto = new MotoBike();
Console.WriteLine("---------------------第三題-----------------------------");
//3、某學(xué)校對教師每月工資的計算公式如下:固定工資 + 課時補(bǔ)貼摔癣。
//專家級講師的的固定工資為25000元,每個課時補(bǔ)貼60元奴饮;
//高級講師的固定工資為18000元,每個課時補(bǔ)貼50元;
//普通講師的固定工資為12000元,每個課時補(bǔ)貼40元。
//定義教師抽象類,派生不同職稱的教師類,編寫程序求若干教師的月工資
Teacher zj = new ZhuangjiaTeacher(10);//參數(shù)為總課時補(bǔ)貼
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} 課時補(bǔ)貼是:{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} 課時補(bǔ)貼是:{1} 總工資是:{2}", this.Gongzi, this.Butie, this.Gongzi + this.Butie);
}
}
abstract class Teacher
{
private int gongzi;//工資
private int butie;//補(bǔ)貼
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} 課時補(bǔ)貼是:{1} 總工資是:{2}", this.Gongzi,this.Butie,this.Gongzi+this.Butie);
}
}