• 面向对象实例----看电视


    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()+"频道");
        }
        
    
    }
  • 相关阅读:
    下载linux历史版本
    CentOS7 常用命令集合
    oracle初级系列教程
    redis内存数据的持久化方式
    使用Spring 或Spring Boot实现读写分离( MySQL实现主从复制)
    三个线程ABC,交替打印ABC
    wait,notify,notifyAll详细介绍
    索引优化分析
    Git常用命令使用大全
    长连接 、短连接、心跳机制与断线重连(转载)
  • 原文地址:https://www.cnblogs.com/2206411193qzb/p/7454936.html
Copyright © 2020-2023  润新知