某城市要举办才艺大赛,目前在海选状态,只要有才艺,就可以参加海选,由相关的人员检查才艺。目前猴子和老虎已经参加海选,还有很多动物都想参加,请写代码描述这个过程。
1.定义接口Performable,包含方法 play
2.定义Monkey类实现该接口,重写方法play,输出“Monkey翻跟头”
3.定义Lion类实现该接口,重写方法play,输出Lion唱摇滚"
4.定义Coach类,该类有方法check,来海选每一个选手,让选手调用play方法展示才艺
5.Main 类 main方法,创建Coach类对象,调用check方法,分别海选monkey对象和Lion对象。
输入格式:
输出格式:
输出猴子和狮子的才艺展示
输入样例:
在这里给出一组输入。例如:
输出样例:
在这里给出相应的输出。例如:
Monkey翻跟头
Lion唱摇滚
AC:
package com.itheima.demo;//PTA需要删除
import javax.swing.*;//PTA需要删除
import java.util.Scanner;
interface Performance{
public void play();
}
class Monkey implements Performance{
public void play(){
System.out.println("Monkey翻跟头");
}
}
class Lion implements Performance{
public void play(){
System.out.println("Lion唱摇滚");
}
}
class Coach {
public void check(){
Monkey a=new Monkey();
Lion b=new Lion();
a.play();
b.play();
}
}
public class Main{
public static void main(String[] args) {
Scanner s =new Scanner(System.in);
Coach zll=new Coach();
zll.check();
}
}