java宠物商店源码_petshop2.0java宠物商店 源代码.doc

本文档提供了Java宠物商店PetShop2.0的源代码,包括Pet、Dog、Cat和Mouce四个类。Pet类作为基类,Dog、Cat和Mouce分别继承Pet,添加各自特性的实现。PetShop类用于管理宠物,具有添加宠物的功能,当宠物数量达到上限时会提示无法添加。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值