老师,这是我修改过后的作业,你看下这样可以吗
package com.circus.www; //棕熊类 public class Bear extends Animal implements IAct { public Bear(){ } public Bear(String name,int age){ //super.name=name; //super.age=age; System.out.println("表演者:"+name+"\n"+"年龄:"+age+"岁"); } public void love(){ System.out.println("爱好:喜欢卖萌"); } @Override public void skill() { // TODO Auto-generated method stub System.out.println("技能:挽着花篮,打着雨伞,自立走秀"); } @Override public void act() { // TODO Auto-generated method stub } @Override public void dress() { // TODO Auto-generated method stub } }
package com.circus.www; //鹦鹉类 public class Parrot extends Animal implements IAct { private String type;//品种属性 public Parrot(){ } public Parrot(String name,int age,String type){ this.setType(type); System.out.println("表演者:"+name+"\n"+"年龄:"+age+"岁"+"\n"+"品种:"+this.getType()); } public void love(){ System.out.println("爱好:喜欢吃坚果和松子"); } public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public void skill() { // TODO Auto-generated method stub System.out.println("技能:擅长模仿"); } @Override public void act() { // TODO Auto-generated method stub } @Override public void dress() { // TODO Auto-generated method stub } }
package com.circus.www; //猴子类 public class Monkey extends Animal implements IAct { private String type;//品种属性 public Monkey(){ } public Monkey(String name,int age,String type){ this.setType(type); System.out.println("表演者:"+name+"\n"+"年龄:"+age+"岁"+"\n"+"品种:"+this.getType()); } public void love(){ System.out.println("爱好:喜欢模仿人的动作表情"); } public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public void skill() { // TODO Auto-generated method stub System.out.println("技能:骑独轮车过独木桥"); } @Override public void act() { // TODO Auto-generated method stub } @Override public void dress() { // TODO Auto-generated method stub } }
package com.circus.www; //小丑类 public class Clown implements IAct { private String name;//小丑姓名 private int years;//小丑艺龄 public Clown(){ } public Clown(String name,int years){ this.setName(name); this.setYears(years); System.out.println("表演者:"+this.getName()+"\n"+"艺龄:"+this.getYears()+"岁"); } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getYears() { return years; } public void setYears(int years) { this.years = years; } //描述着装特点 public void dress(){ System.out.println("着装:身穿五彩服装,头上戴着彩色的帽子,脸上画着夸张的彩妆"); } @Override public void skill() { // TODO Auto-generated method stub System.out.println("技能:脚踩高跷,进行杂技魔术表演"); } @Override public void act() { // TODO Auto-generated method stub } @Override public void love() { // TODO Auto-generated method stub } }
package com.circus.www; //狮子类 public class Lion extends Animal implements IAct { private String color;//颜色属性 private String sex;//性别属性 public Lion(){ } public Lion(String color,String sex,String name,int age){ this.setColor(color); this.setSex(sex); System.out.println("表演者:"+name+"\n"+"年龄:"+age+"岁"+"\n"+"性别:"+this.getSex()+"\n"+"毛色:"+this.getColor()); } public void love(){ System.out.println("爱好:爱吃各种肉类"); } public String getColor() { return color; } public void setColor(String color) { this.color = color; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } @Override public void skill() { // TODO Auto-generated method stub System.out.println("技能:擅长钻火圈"); } @Override public void act() { // TODO Auto-generated method stub } @Override public void dress() { // TODO Auto-generated method stub } }
package com.circus.www; public abstract class Animal { String name;//属性:昵称 int age;//属性:年龄 public abstract void love();//描述喜好(love) }
/** * */ package com.circus.www; /** * @author Administrator * */ public interface IAct { public abstract void skill();//描述技能 public abstract void act();//描述表演 public abstract void love();//爱好 public abstract void dress();//穿着 }
package com.test.www; import java.util.*; import com.circus.www.Bear; import com.circus.www.Clown; import com.circus.www.IAct; import com.circus.www.Lion; import com.circus.www.Monkey; import com.circus.www.Parrot; public class Test { public static void main(String[] args) { // TODO Auto-generated method stub while(true){ System.out.println("******欢迎来到太阳马戏团******"); System.out.println("******请选择表演者******"); System.out.println("******1.棕熊******"); System.out.println("******2.狮子******"); System.out.println("******3.猴子******"); System.out.println("******4.鹦鹉******"); System.out.println("******5.小丑******"); Scanner Random=new Scanner(System.in); int optionOne=Random.nextInt();//option选项 IAct actor=null; switch(optionOne){ case 1:actor=new Bear("Bill", 1);break; case 2:actor=new Lion("灰色","公狮","Lian",2); break; case 3:actor=new Monkey("Tom",1,"金丝猴"); break; case 4:actor=new Parrot("Rose",1,"牡丹鹦鹉"); break; case 5:actor=new Clown("Kahle",5);break; default:System.out.println("表演者不存在,请重新输入"); continue; } if(actor!=null){ actor.act(); actor.skill(); actor.love(); actor.dress(); } //int optionTwo=Random.nextInt(); while(true){ System.out.println("******是否继续观看(1/0)******"); int optionTwo=Random.nextInt(); if(optionTwo==0){ System.out.println("******欢迎下次光临******"); System.exit(0); } else if(optionTwo==1){ break; } else{ System.out.println("***输入信息不正确,请重新输入****"); } } } } }
64
收起
正在回答 回答被采纳积分+1
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星