同步课 / 2014级JavaSE

作业08:实现一个打印机的程序,用户可以使用不同的打印机打印各种文件
10
王伟
开始于 2016-03-16 13:34
0 33 157
已截止

任务尚未发布或者你没有权限查看任务内容。

任务讨论
王伟

任务已更新

/**
 * 作业:实现一个打印机的程序,用户可以使用不同的打印机打印各种文件
 * 姓名:王晓旺
 * 学号:2014011739
 * 班级:5班
 */
//DocumentType.java
package com.works2.www;

public interface DocumentType {

	public String printContent();

	abstract String getHead();

	abstract String getContent();

	abstract String getFoot();
}
//DocumentType.java
package com.works2.www;

public abstract  class AbstractDocumentType implements DocumentType {
	private String content;

	public String printContent() {
	
		return content;
	}

	public abstract String getHead();

	public abstract String getContent();

	public abstract String getFoot();

}
// AbstractDocumentType.java
package com.works2.www;

public class StudentReport extends AbstractDocumentType {
	private String head;
	private String content;
	private String foot;

	public StudentReport(String head, String content, String foot) {
		this.head = head;
		this.content = content;
		this.foot = foot;
	}

	public String getHead() {
		return head;
	}

	public String getContent() {
		return content;
	}

	public String getFoot() {
		return foot;
	}
}
// AbstractDocumentType.java
package com.works2.www;

public class TeacherReport extends AbstractDocumentType {
	private String head;
	private String content;
	private String foot;

	public TeacherReport(String head, String content, String foot) {
		this.head = head;
		this.content = content;
		this.foot = foot;
	}

	public String getHead() {
		return head;
	}

	public String getContent() {
		return content;
	}

	public String getFoot() {
		return foot;
	}
}
//Printable.java
package com.works2.www;

public interface Printable {
	public abstract void print(DocumentType dt);
}
//JiGuangPrinter.java
package com.works2.www;

public class JiGuangPrinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println("激光打印:" + dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//PenMoPrinter.java
package com.works2.www;

public class PenMoPrinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println("喷墨打印:" + dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//DianZhenPinter.java
package com.works2.www;

public class DianZhenPinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println( "电帧打印:"+dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//Test.java
package com.works2.www;

public class Test {

	public static void main(String[] args) {
		StudentReport p = new StudentReport("师大", "软件", "学生");
		TeacherReport q = new TeacherReport("师大 ", "软件", "老师");
		Printable A = new JiGuangPrinter(), B = new DianZhenPinter(), C = new PenMoPrinter();
		A.print(p);
		A.print(q);
		B.print(p);
		B.print(q);
		C.print(p);
		C.print(q);
	}

}
/**
 * 作业:实现一个打印机的程序,用户可以使用不同的打印机打印各种文件
 * 姓名:王晓旺
 * 学号:2014011739
 * 班级:5班
 */
//DocumentType.java
package com.works2.www;

public interface DocumentType {

	public String printContent();

	abstract String getHead();

	abstract String getContent();

	abstract String getFoot();
}
//DocumentType.java
package com.works2.www;

public abstract  class AbstractDocumentType implements DocumentType {
	private String content;

	public String printContent() {
	
		return content;
	}

	public abstract String getHead();

	public abstract String getContent();

	public abstract String getFoot();

}
// AbstractDocumentType.java
package com.works2.www;

public class StudentReport extends AbstractDocumentType {
	private String head;
	private String content;
	private String foot;

	public StudentReport(String head, String content, String foot) {
		this.head = head;
		this.content = content;
		this.foot = foot;
	}

	public String getHead() {
		return head;
	}

	public String getContent() {
		return content;
	}

	public String getFoot() {
		return foot;
	}
}
// AbstractDocumentType.java
package com.works2.www;

public class TeacherReport extends AbstractDocumentType {
	private String head;
	private String content;
	private String foot;

	public TeacherReport(String head, String content, String foot) {
		this.head = head;
		this.content = content;
		this.foot = foot;
	}

	public String getHead() {
		return head;
	}

	public String getContent() {
		return content;
	}

	public String getFoot() {
		return foot;
	}
}
//Printable.java
package com.works2.www;

public interface Printable {
	public abstract void print(DocumentType dt);
}
//JiGuangPrinter.java
package com.works2.www;

public class JiGuangPrinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println("激光打印:" + dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//PenMoPrinter.java
package com.works2.www;

public class PenMoPrinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println("喷墨打印:" + dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//DianZhenPinter.java
package com.works2.www;

public class DianZhenPinter implements Printable {
	public void print(DocumentType dt) {
		System.out.println( "电帧打印:"+dt.getHead() + " " + dt.getContent() + " " + dt.getFoot());
	}
}
//Test.java
package com.works2.www;

public class Test {

	public static void main(String[] args) {
		StudentReport p = new StudentReport("师大", "软件", "学生");
		TeacherReport q = new TeacherReport("师大 ", "软件", "老师");
		Printable A = new JiGuangPrinter(), B = new DianZhenPinter(), C = new PenMoPrinter();
		A.print(p);
		A.print(q);
		B.print(p);
		B.print(q);
		C.print(p);
		C.print(q);
	}

}