当前位置:   article > 正文

看电视_对看电视这个场景写java代码 site:blog.csdn.net

对看电视这个场景写java代码 site:blog.csdn.net

TV.java

  1. public class TV {
  2. int channel;
  3. void setChannel(int x) {
  4. channel = x;
  5. }
  6. int getChannel() {
  7. return channel;
  8. }
  9. void showProgram() {
  10. switch (channel) {
  11. case 1:
  12. System.out.println("新闻频道");
  13. break;
  14. case 2:
  15. System.out.println("音乐频道");
  16. break;
  17. case 3:
  18. System.out.println("戏曲频道");
  19. break;
  20. case 4:
  21. System.out.println("英语频道");
  22. break;
  23. case 5:
  24. System.out.println("相声频道");
  25. break;
  26. case 6:
  27. System.out.println("湖南卫视");
  28. break;
  29. case 7:
  30. System.out.println("天津卫视");
  31. break;
  32. case 8:
  33. System.out.println("山东卫视");
  34. break;
  35. case 9:
  36. System.out.println("江西卫视");
  37. break;
  38. case 10:
  39. System.out.println("西藏卫视");
  40. break;
  41. default:
  42. System.out.println("请换频道");
  43. break;
  44. }
  45. }
  46. }

Family.java

  1. public class Family {
  2. TV television;
  3. void buyTV(TV tv) {
  4. television = tv;
  5. }
  6. void remoteControl(int m) {
  7. television.setChannel(m);
  8. }
  9. void seeTV() {
  10. television.showProgram();
  11. }
  12. }


Acheive.java

  1. import java.util.*;
  2. public class Acheive {
  3. /**
  4. * @param args
  5. */
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8. TV Haier = new TV();
  9. Family zhangsan = new Family();
  10. zhangsan.buyTV(Haier);
  11. System.out.println("请选择您喜欢的频道:");
  12. Scanner scanner = new Scanner(System.in);
  13. int channel = scanner.nextInt();
  14. zhangsan.remoteControl(channel);
  15. zhangsan.seeTV();
  16. }
  17. }


请选择您喜欢的频道:
10
西藏卫视


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/475623
推荐阅读
相关标签
  

闽ICP备14008679号