赞
踩
TV.java
- public class TV {
- int channel;
-
- void setChannel(int x) {
- channel = x;
- }
-
- int getChannel() {
- return channel;
- }
-
- void showProgram() {
- switch (channel) {
- case 1:
- System.out.println("新闻频道");
- break;
- case 2:
- System.out.println("音乐频道");
- break;
- case 3:
- System.out.println("戏曲频道");
- break;
- case 4:
- System.out.println("英语频道");
- break;
- case 5:
- System.out.println("相声频道");
- break;
- case 6:
- System.out.println("湖南卫视");
- break;
- case 7:
- System.out.println("天津卫视");
- break;
- case 8:
- System.out.println("山东卫视");
- break;
- case 9:
- System.out.println("江西卫视");
- break;
- case 10:
- System.out.println("西藏卫视");
- break;
- default:
- System.out.println("请换频道");
- break;
- }
- }
- }
Family.java
- public class Family {
- TV television;
-
- void buyTV(TV tv) {
- television = tv;
- }
- void remoteControl(int m) {
- television.setChannel(m);
- }
- void seeTV() {
- television.showProgram();
- }
- }
-
Acheive.java
- import java.util.*;
- public class Acheive {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- TV Haier = new TV();
- Family zhangsan = new Family();
- zhangsan.buyTV(Haier);
- System.out.println("请选择您喜欢的频道:");
- Scanner scanner = new Scanner(System.in);
- int channel = scanner.nextInt();
- zhangsan.remoteControl(channel);
- zhangsan.seeTV();
-
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。