Java Learning 8: Practical Object-Oriented Programming (Beijing University & Xidian Experimental Content): The first topic: "The Flying World"

The first topic: Teacher Tang from Beijing University

Insert picture description here
There are four choices here, and all four of us will do it:

The first sub-topic: the flying world: a flying relay

package Main;

public class Main{
    
    
	static int FlyLen = 1000;
	static int AllTime = 0;
	static String MVPName = "";
	static int EveFly = 0;
	static int MVPFly = 0;
	public static void main(String[] args){
    
    
		Bird bird = new Bird("鸽子", 6, 20, 5, 2, 3, "扇翅膀", 100);
		
		AirPlane ap = new AirPlane(800, "China", 100, 10, 20, 4, "波音747");
		
		int i = 1;
		while(FlyLen > 0) {
    
    
			if(1 == i % 2) {
    
     
				System.out.println("现在出场的是第 " + i + " 位选手:" + bird.GetterName());
				System.out.println("快看:它起飞了!");
				bird.SetOff(bird.GetterAct(), bird.GetterUpTime());
				bird.FlyTim(bird.GetterHigh(), bird.GetterTimeOnce());
				bird.SetDow(bird.GetterAct(), bird.GetterDownTime());
				Main.AllTime += bird.GetterAllTime();
				Main.EveFly++;
				Main.FlyLen -= bird.GetterTimeOnce() * bird.GetterFly();
				if(Main.MVPFly < bird.GetterFly()) {
    
    
					Main.MVPFly = bird.GetterFly();
					Main.MVPName = bird.GetterName();
				}
				System.out.println();
			}
			else {
    
    
				System.out.println("现在出场的是第 " + i + " 位选手:" + ap.GetterName());
				System.out.println("快看:它起飞了!");
				ap.SetOff(ap.GetterUpTime());
				ap.FlyTim(ap.GetterTimeOnce());
				ap.SetDow(ap.GetterDownTime());
				Main.AllTime += ap.GetterAllTime();
				Main.EveFly++;
				Main.FlyLen -= ap.GetterTimeOnce() * ap.GetterFly();
				if(Main.MVPFly < ap.GetterFly()) {
    
    
					Main.MVPFly = ap.GetterFly();
					Main.MVPName = ap.GetterName();
				}
			}
			i++;
			System.out.println();
		}
		System.out.println("激烈的接力赛终于是结束了!!!揭晓今天的MVP是:" + Main.MVPName + ",它的飞翔能力是:" + Main.MVPFly);
	}	
}

interface WanaFly {
    
    
	abstract void SetOff(String Act, int Time);
	abstract void FlyTim(int High, int Time);
	abstract void SetDow(String Act, int Time);
}

abstract class Animal{
    
    
	protected String name;
	int age;
	int FlyEng;// 飞翔能力:每分钟能够飞多远
	Animal(String name, int age, int FlyEng){
    
    
		this.name = name;
		this.age = age;
		this.FlyEng = FlyEng;
	}
	abstract void Discribe();
}

class Bird extends Animal implements WanaFly {
    
    
	private int TimeOnce;// 一次飞翔能坚持的时间
	private int UpTime;
	private int DownTime;
	private String Act;
	private int High;
	
	public int GetterTimeOnce() {
    
    
		return this.TimeOnce;
	}
	
	public int GetterAllTime() {
    
    
		return this.TimeOnce + this.UpTime + this.DownTime;
	}
	
	public int GetterUpTime() {
    
    
		return this.UpTime;
	}
	
	public int GetterDownTime() {
    
    
		return this.DownTime;
	}
	
	public String GetterAct() {
    
    
		return this.Act;
	}
	
	public int GetterHigh() {
    
    
		return this.High;
	}
	
	public String GetterName() {
    
    
		return this.name;
	}
	
	public int GetterFly() {
    
    
		return super.FlyEng;
	}
	
	public Bird(String name, int age, int FlyEng, int TimeOnce, int UpTime, int DownTime, String Act, int High){
    
    
		super(name, age, FlyEng);
		this.TimeOnce = TimeOnce;
		this.UpTime = UpTime;
		this.DownTime = DownTime;
		this.Act = Act;
		this.High = High;
	}
	
	public void Discribe() {
    
    
		System.out.println("这只鸟的名字叫:" + this.name + ",它的年龄是:" + this.age + ",它的飞行能力是:" + this.FlyEng + "每分钟");
	}
	
	public void SetOff(String Act, int Time) {
    
    
		System.out.println(this.name + "的起飞姿势是:" + Act + ",它起飞的时间是:" + Time);
	}
	
	public void FlyTim(int High, int Time) {
    
    
		System.out.println(this.name + "它的飞翔能达到的高度是:" + High + "在这个高度下它能飞:" + Time);
	}
	
	public void SetDow(String Act, int Time) {
    
    
		System.out.println(this.name + "的降落姿势是:" + Act + ",它的降落用时:" + Time);
	}
}

abstract class Vehicle{
    
    
	int price;
	String BuiFie;
	int FlyEng;
	
	Vehicle(int price, String BuiFie, int FlyEng) {
    
    
		this.price = price;
		this.BuiFie = BuiFie;
		this.FlyEng = FlyEng;
	}
}

class AirPlane extends Vehicle {
    
    
	private int UpTime;
	private int DownTime;
	private int TimeOnce;
	private String name;
	
	AirPlane(int price, String BuiFie, int FlyEng, int UpTime, int DownTime, int TimeOnce, String name) {
    
    
		super(price, BuiFie, FlyEng);
		this.UpTime = UpTime;
		this.DownTime = DownTime;
		this.TimeOnce = TimeOnce;
		this.name = name;
	}
	
	public int GetterAllTime() {
    
    
		return this.TimeOnce + this.UpTime + this.DownTime;
	}
	
	public int GetterTimeOnce() {
    
    
		return this.TimeOnce;
	}
	
	public int GetterUpTime() {
    
    
		return this.UpTime;
	}
	
	public int GetterDownTime() {
    
    
		return this.DownTime;
	}
	
	public String GetterName() {
    
    
		return this.name;
	}
	
	public int GetterFly() {
    
    
		return super.FlyEng;
	}
	
	public void SetOff(int Time) {
    
    
		System.out.println(this.name + " 起飞需要的时间是:" + Time);
	}
	
	public void FlyTim(int Time) {
    
    
		System.out.println(this.name + " 飞翔需要的时间是:" + Time);
	}
	
	public void SetDow(int Time) {
    
    
		System.out.println(this.name + " 降落需要的时间是:" + Time);
	}
}

The result of the flying world is:

Insert picture description here

Remarks:

The amount of code for this experiment is relatively large! ! There are about 6 questions in total, let's do it slowly! !
If you have any questions or good suggestions, I hope to comment or chat with me privately! ! I hope that my colleagues from the predecessors will advise me on my code. Thanks a lot! !

Guess you like

Origin blog.csdn.net/qq_44274276/article/details/105008863