【java实现宠物商店(查找宠物,添加宠物功能).md】代码如图:
主要是练习一下对象的多态和接口的使
interface Pet{
public String getName();
public String getColor();
public int getAge();
}
class Cat implements Pet{
private String name;
private String color;
private int age;
public Cat(String name,String color,int age)
{
this.name=name;
this.color=color;
this.age= 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;
}
}
class Dog implements Pet{
private String name;
private String color;
private int age;
public Dog(String name,String color,int age)
{
this.name=name;
this.color=color;
this.age= 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;
}
}
class PetShop{
private Pet[] petArray;
private int foot;
public PetShop(int len)
{
if(len>0)
this.petArray= new Pet[len];
else
this.petArray=new Pet[1];
}
public Pet[] getPetArray() {
return petArray;
}
public void setPetArray(Pet[] petArray) {
this.petArray = petArray;
}
public int getFoot() {
return foot;
}
public void setFoot(int foot) {
this.foot = foot;
}
public void addPet(Pet pet)
{
if(foot
推荐阅读
- ace File-Input实现图片上传功能+colorBox显示图片
- java学习|【算法学习】链表数相加(Java)
- Java学习|ArrayList源码浅析
- Java学习|HashMap浅析
- Java学习|Android中的位运算
- Java中二维数组的拷贝方式
- java数组截取
- java数组拼接
- 图像处理|基于投影的字符版面分析java代码
- java学习|excel导出(使用window.open的post请求方式)