Java学习8:面向对象编程实战(北大 & 西电实验内容):第一小题:《飞翔的世界》
作者:互联网
第一大题:来自北大唐老师
这里有四个选题,我们四个都去做:
第一小题:飞翔的世界:来一次飞翔接力
package Main;
public class Main{
static int FlyLen = 1000;
static int AllTime = 0;
static String M***ame = "";
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.M***ame = 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.M***ame = ap.GetterName();
}
}
i++;
System.out.println();
}
System.out.println("激烈的接力赛终于是结束了!!!揭晓今天的MVP是:" + Main.M***ame + ",它的飞翔能力是:" + 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);
}
}
飞翔的世界结果是:
备注:
这次的实验代码量比较大哦!!大概一共6道题,咱们慢慢做吧!!
有什么问题或者好的建议的,希望能评论或者私聊我哦!!更加希望有前辈同仁对我的代码进行指教,多多感谢!!
标签:Java,name,int,西电,bird,面向对象编程,Main,public,String 来源: https://blog.51cto.com/u_15262702/2883279