正在回答 回答被采纳积分+1
3回答
未知数X
2017-12-06 22:18:15
public class TestAnimal { //表演的菜单显示 public void notice() { System.out.println("************欢迎来到太阳马戏团***************"); System.out.println("*******请选择表演者***********"); System.out.println("********* 1、熊 ***************"); System.out.println("********* 2、狮子 ***************"); } // 表演是否继续判断 public void notice2() { System.out.println("************是否继续观看(0/1)**************"); } public static void main(String[] agrs) { TestAnimal ms = new TestAnimal(); boolean flag = true; Scanner sc = new Scanner(System.in); int[] a = new int[5]; while (flag) { ms.notice(); int n = sc.nextInt(); switch (n) { case 1: // Bear Animal a1 = new Bear("Bill", 1); if (a1 instanceof Bear) { Bear temp = (Bear) a1; temp.atc(); temp.skill(); temp.love(); }break; case 2: //Lion Animal a2 = new Lion("Lain", 2, "灰色", "公狮"); if (a2 instanceof Lion) { Lion temp2 = (Lion) a2; temp2.atc(); temp2.skill(); temp2.love(); }break; default: ms.notice2(); while (flag) { Scanner sc2 = new Scanner(System.in); int n2 = sc2.nextInt(); switch (n2) { case 1: ms.notice(); break; case 2: System.out.println("表演结束"); flag = false; break; } } } } } }
Java零基础入门18
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星