求宠物管理系统Java代码 , 具有增删改查功能 , 用数组实现,并且有输入功能你说养小猫的java代码的是网上流传的宠物商店web版的代码吧
Java版本的名字叫养小猫的java代码:J2EE Java Pet Store
.NET版本的叫养小猫的java代码:.NET PetShop
百度一下J2EE Java Pet Store养小猫的java代码,这是一套经典示例代码
一道java编程题,请各位大神前来解答代码如下养小猫的java代码:
abstract class Animal {
private String name;
public Animal(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public abstract void enjoy();
}
class Cat extends Animal {
private String eyesColor;
public Cat(String name) {
super(name);
}
public String getEyesColor() {
return eyesColor;
}
public void setEyesColor(String eyesColor) {
this.eyesColor = eyesColor;
}
@Override
public void enjoy() {
System.out.println("小猫" + getName() + "高兴养小猫的java代码的喵喵叫 。");
}
}
class Dog extends Animal {
private String furColor;
public Dog(String name) {
super(name);
}
public String getFurColor() {
return furColor;
}
public void setFurColor(String furColor) {
this.furColor = furColor;
}
@Override
public void enjoy() {
System.out.println("狗狗" + getName() + "高兴的摇起养小猫的java代码了尾巴 。");
}
}
class Lady {
private String name;
private Animal pet;
public Lady(String name, Animal pet) {
this.name = name;
this.pet = pet;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Animal getPet() {
return pet;
}
public void setPet(Animal pet) {
this.pet = pet;
}
public void myPetEnjoy() {
pet.enjoy();
}
}
public class App {
public static void main(String[] args) {
Cat cat = new Cat("Jerry");
cat.setEyesColor("蓝色");
Lady lady1 = new Lady("张女士", cat);
lady1.myPetEnjoy();
Dog dog = new Dog("旺财");
dog.setFurColor("黄色");
Lady lady2 = new Lady("王女士", dog);
lady2.myPetEnjoy();
}
}
用Java程序完成以下场景(用继承多态):有一个主人(Master类),他养了两只宠物(Pet类)public class Run {
public static void main(String[] args) {
Master master = new Master();
master.feedDog("鸡骨头");
master.feedCat("鸡骨头");
}
}
class Master {
private Pet mPet;
private Food mFood;
public void feedCat(String food) {
mPet = new Cat();
mFood = new Food(food);
mPet.eat(mFood);
}
public void feedDog(String food) {
mPet = new Dog();
mFood = new Food(food);
mPet.eat(mFood);
}
}
class Dog extends Pet{
@Override
public void eat(Food food) {
System.out.println("正在喂小狗吃"+food.getFood());
if (food.getFood().matches(Food.BONE)) {
System.out.println("小狗正在吃"+food.getFood()+"养小猫的java代码!");
}else {
System.out.println("但是小狗不喜欢吃"+food.getFood()+"!");
}
}
}
class Cat extends Pet{
@Override
public void eat(Food food) {
System.out.println("正在喂小猫吃"+food.getFood());
if (food.getFood().matches(Food.FISH)) {
System.out.println("小猫正在吃"+food.getFood()+"养小猫的java代码!");
}else {
System.out.println("但是小猫不喜欢吃"+food.getFood()+"!");
推荐阅读
- 电脑如何安装鸿蒙os2.0电脑端,电脑如何安装鸿蒙系统pc版
- 霍金是什么病视频,霍金的病是
- 静物拍摄家用什么灯,静物拍摄家用什么灯好
- linux脚本制作命令,linux 编写脚本
- php监控数据库设置 php监控文件变化
- 光纤和路由器怎么设置,光纤路由器怎么设置ip地址
- 计算机毕业设计分哪些步骤,计算机类毕业设计怎么做
- 免登录低配版射击游戏,不用登录的射击小游戏
- 怎么再黑窗口进MySQL 怎么用黑窗口打开mysql