zoukankan      html  css  js  c++  java
  • 打印机__接口

    package Print;
    
    public interface Ink {
        
        void ink(String content);
    }
    package Print;
    
    public class BlackInk implements Ink{
    
        @Override
        public void ink(String content) {
            System.out.println("使用黑墨水");
        }
        
    }
    package Print;
    
    public class ColorfulInk implements Ink{
    
        @Override
        public void ink(String content) {
            System.out.println("使用彩墨水");
        }
        
    }
    package Print;
    
    public interface Paper{
    
        void paper(String content);
        
    }
    package Print;
    
    public class A4Paper implements Paper{
    
        @Override
        public void paper(String content) {
            System.out.println("使用A4纸打印");
        }
        
    }
    package Print;
    
    public class B5Paper implements Paper{
    
        @Override
        public void paper(String content) {
            System.out.println("使用B5纸打印");
        }
    }
    package Print;
    
    public class Print {
        private Ink ink;
        private    Paper paper;
        public Paper getPaper() {
            return paper;
        }
        public void setPaper(Paper paper) {
            this.paper = paper;
        }
        public Ink getInk() {
            return ink;
        }
        public void setInk(Ink ink) {
            this.ink = ink;
        }
        public void print(String content){
            System.out.println("开始打印:");
            ink.ink(content);
            paper.paper(content);
            System.out.println("打印结果:"+content);
            System.out.println("打印结束");
            
        }
    }
    package Print;
    
    public class PrintTest {
    
        public static void main(String[] args) {
            Print print = new Print();
            print.setInk(new BlackInk());
            print.setPaper(new A4Paper());
            print.print("567");
        }
    
    }

  • 相关阅读:
    ES6-->ECMAScript 6.0 新增方法,一些基本语法
    初识 Nodejs (了解Nodejs)
    Vue框架初识
    python语法入门之流程控制
    python中基本运算符
    格式化输出
    基本数据类型
    变量,解释器,垃圾回收机制,小整数池总结
    编程语言发展史
    计算机基础
  • 原文地址:https://www.cnblogs.com/xiaolei121/p/5753405.html
Copyright © 2011-2022 走看看