一道java考试试题求解 - 爱问答

(爱问答)

一道java考试试题求解

A customer visits a restaurant and asks for service via a bell.

The waiter receives the bell ring and answers. 

The Waiter class implements the Bell interface, 

and the Customer class contains a method called served(),

representing that he is served by the waiter. 

served() calls Bell's answer().

 

Please complete the codes.

For example:

input: 10

output: 

Waiter 10 receives a bell ring.

the customer is served.


只能在shart 和 end之间添加代码。


源代码

import java.util.Scanner;

 

interface Bell {

void answer();

}

 

/******start******/

 

/******end******/

 

public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int no = scanner.nextInt();

 

Bell bell=new Waiter(no);

Customer customer=new Customer(bell);

 

customer.served();

 

scanner.close();

}

}


完整的参考

/******start******/
class Waiter  implements Bell {
   public Waiter(int n) {
       System.out.printf("Waiter %d receives a bell ring. ",n);
   }
   public  void answer() {
       System.out.printf("the customer is served.");
   }
}
class Customer {
   Bell bell;
   public Customer(Bell b) {
       bell=b;
   }
   public void served() {
      bell.answer();
   }
}
/******end******/

相关标签:java

下一篇:4m-9n=0,n/m-m/n=

上一篇:学校买了360个毽子,全校有18个班,也买了220根跳绳,学校平均每班可以得多少个毽子,多少个跳

热门标签:
英语 谜语 作文 数学 公式 语文 物理 化学 工艺 java c语言 实验 方程 金属 分子 数据库 硫酸 酒精 运算 石油 vc 世界大战 php 化合物 mysql
最新更新:
电学的一个小问题 为什么打点计时器只能粗略瞬时速度 lookdownupon用法 中专都考不上大学有必要复读一年吗? 如图,已知∠B=∠DEF,AB=DE,请添加一个条件使△ABC≌△DEF,则需添加的条件是__________. 求曲线y=2x^2和直线y=2的所围图形的面积 夜上受降城闻笛是哪句 这个怎么填数字? 小明家下五层楼是5楼,那么小明家上五层楼是几层楼? 填空题,这个题目是怎么算的呢…… 22335577()143中括号里填什么数字。 懂得人帮我看一下这个英文是啥意思??? 最小的物质单位是什么 怎么估算根号52000000 about的重读字母是哪里