petshop2.0java宠物商店 源代码
PetShop2.0
(应用继承extends)
Pet.java
public class Pet{
private String name;
private String color;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Pet(String name, String color, int age) {
super();
this.name = name;
this.color = color;
this.age = age;
}
}
Dog.java
public class Dog extends Pet {
private String type;
public Dog(String name, String color, int age, String type) {
super(name, color, age);
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void eat(){
System.out.println("I like eating bone!");
}
}
Cat.java
public class Cat extends Pet {
private double weight;
public Cat(String name, String color, int age, double weight) {
super(name, color, age);
this.weight = weight;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public void eat(){
System.out.println("I like eating fish!");
}
}
Mouce.java
public class Mouce extends Pet{
private String sex;
public Mouce(String name, String color, int age, String sex) {
super(name, color, age);
this.sex = sex;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
PetShop.java
public class PetShop {
private Pet[] pets;
private int petActuralCount;
public static final int PET_COUNT=100;
public PetShop(){
super();
pets=new Pet[PET_COUNT];
}
public boolean add(Pet pet){
boolean result=false;
if(petActuralCount
{
pets[petActuralCount]=pet;
petActuralCount++;
result=true;
return result;
}else
{
System.out.println("the houses of pets are full!");
return result;
}
}
public void