zoukankan      html  css  js  c++  java
  • 面向对象实例----看电视

    import java.util.Scanner;
    
    public class enum1 {
    
        public static void main(String[] args) {
            proxyRequst a = new saler();
            a.request();
            Scanner sc = new Scanner(System.in);
            int x = sc.nextInt();
            TV hairerTV = new TV();
            hairerTV.setChannel(x);
            System.out.println("卖给用户hairTV目前的频道是:"+hairerTV.getChannel());
            Chineses zhangzhi = new Chineses();
            zhangzhi.buyTV(hairerTV);
            System.out.println("zhangzhi开始看电视节目");
            zhangzhi.seeTV();
            int m;
            System.out.print("请输入zhangzhi要看的频道:");
            m = sc.nextInt();
            System.out.println("zhangzhi将买回来的电视更改到"+m+"频道");
            zhangzhi.remoteControl(m);
            System.out.println("现在卖给用户的电视频道是"+hairerTV.getChannel());
            System.out.println("zhangzhi在看电视");
            zhangzhi.seeTV();
        }
    }
    interface proxyRequst
    {
        abstract public void request();
    }
    class hairerTVFactory implements proxyRequst
    {
        public void request()
        {
            System.out.println("我是海尔公司,我想要设置初始频道为:");
        }
    }
    class saler implements proxyRequst{
        
        private hairerTVFactory a;
        public void request()
        {  
            if(a==null)
            {
                a = new hairerTVFactory();
                a.request();
            }
            
        }
    }
    class TV
    {
        int channel;
        void setChannel(int m)
        {
            if(m>=1)
            {
                channel = m;
            }
        }
        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;    
            default:System.out.println("不能看"+channel+"频道");
        }
        }
    }
    class Chineses
    {
        TV homeTV;
        void buyTV(TV tv)
        {
        homeTV  = tv;
        }
        void remoteControl(int m){
            homeTV.setChannel(m);
        }
        void seeTV(){
            homeTV.showProgram();
            System.out.println("用户买回来的电脑是在"+homeTV.getChannel()+"频道");
        }
        
    
    }
  • 相关阅读:
    Eclipse的安装及汉化图解
    Intent常用使用汇总
    Android Notification (转)
    垃圾回收
    svn常见错误汇总
    位运算
    FusionCharts简单教程(一)---建立第一个FusionCharts图形
    Delphi发送邮件...
    协程库的一些笔记
    学习日记之单例模式和Effective C++
  • 原文地址:https://www.cnblogs.com/2206411193qzb/p/7454936.html
Copyright © 2011-2022 走看看