小狗编程代码(小狗编程软件)

2023-12-21 08:17:36 数码极客 bianji01

 

java编程急急急

packagecom.common;

publicinterfaceDogState{

publicvoidshowState();

packagecom.common;

publicclassDog{

privateDogStatestate;

publicDogStategetState(){

returnstate;

publicvoidsetState(DogStatestate){

this.state=state;

publicvoidshow(){

state.showState();

packagecom.common.impl;

importcom.common.DogState;

publicclassMeetingDogsimplementsDogState{

publicvoidshowState(){

System.out.println("狗的状态为:上前,嬉闹");

packagecom.common.impl;

importcom.common.DogState;

publicclassMeetingEnemyimplementsDogState{

publicvoidshowState(){

System.out.println("狗的状态为:吠叫,很可能咬敌人");

packagecom.common.impl;

importcom.common.DogState;

publicclassMeetingFriendsimplementsDogState{

publicvoidshowState(){

System.out.println("狗的状态为:摇摇尾巴,表示欢迎");

packagecom.common.impl;

importcom.common.DogState;

publicclassMeetingHostimplementsDogState{

publicvoidshowState(){

System.out.println("狗的状态为:开心");

packagecom.common;

importcom.common.impl.MeetingDogs;

importcom.common.impl.MeetingEnemy;

importcom.common.impl.MeetingFriends;

importcom.common.impl.MeetingHost;

publicclassTest{

*@paramargs

publicstaticvoidmain(String[]args){

//TODOAuto-generatedmethodstub

Dogdog=newDog();

dog.setState(newMeetingDogs());

dog.show();

dog.setState(newMeetingEnemy());

dog.show();

dog.setState(newMeetingFriends());

dog.show();

dog.setState(newMeetingHost());

dog.show();

这一题java编程题怎么做啊,有点急

代码如下,

****云客宝典技术团队****

答案可以解决您的需求,请将答案设置为采纳,如有不解,可以留言

packagecom.domax.org.abs;

publicabstractclassAnimal{

protectedStringanimalName;

publicabstractvoidhowl();

publicclassCatextendsAnimal

publicCat(StringanimalName){

super();

this.animalName=animalName;

publicvoidhowl(){

System.out.println(this.animalName+"正在喵喵");

publicclassDogextendsAnimal{

publicDog(StringanimalName){

super();

this.animalName=animalName;

@Override

publicvoidhowl(){

//TODOAuto-generatedmethodstub

System.out.println(this.animalName+"正在旺旺");

packagecom.domax.org.abs;

publicclassTest{

publicstaticvoidmain(String[]args){

Catcat=newCat("小猫");

Dogdog=newDog("小狗");

cat.howl();

dog.howl();

声明:易趣百科所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系315127732@qq.com
广告位招租
横幅广告