阅读背景:

有关于面向对象的综合练习——电子宠物练习

来源:互联网 
package com.hanqi.maya.model;

public abstract class Pet {
	private String name;
	private int age;
	private String sex;
	private int happy;
	private int healthy;
	private int hungry;
	private boolean isalive;
	public Pet() {
		super();
	
	}
	public Pet(String name,  String sex) {
		super();
		this.name = name;
		this.age = 1;
		this.sex = sex;
		this.healthy = 80;
		this.hungry = 80;
		this.happy = 80;
		this.isalive = true;
	}
	public int getHappy() {
		return happy;
	}
	public void setHappy(int happy) {
		this.happy = happy;
	}
	public abstract void eat();
	public abstract void play();
	public abstract void drug();
	public abstract void hello();
	public abstract void bye();
	public boolean checkState() {
		if (this.happy < 0) {
			System.out.println("不开心");
		}
		if (this.healthy <= 0) {
			isalive = false;
		}
		if (this.hungry <= 50 && this.hungry > 0) {
			System.out.println("请喂食");
		} else if (this.hungry <= 0) {
			isalive = false;
			System.out.println("挂了");
		}
		return isalive;
	}

	public void show() {
		System.out.println("宠物名称: " + this.name);
		System.out.println("宠物性别: " + this.sex);
		System.out.println("宠物年龄: " + this.age);
		System.out.println("饥饿度: " + this.hungry);
		System.out.println("开心值: " + this.happy);
		System.out.println("健康值: " + this.healthy);
	}

	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public int getHealthy() {
		return healthy;
	}
	public void setHealthy(int healthy) {
		this.healthy = healthy;
	}
	public int getHungry() {
		return hungry;
	}
	public void setHungry(int hungry) {
		this.hungry = hungry;
	}
	public boolean getIsalive() {
		return isalive;
	}
	public void setIsalive(boolean isalive) {
		this.isalive = isalive;
	}


}
package com.hanqi.maya.model;

public abstr



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: