1、福建工程学院/1.接口public interface Tell public String tell();/2.教师 (Teacher)类class Teacher implements Tell福建工程学院public Teacher(String teacher)this.teacher = teacher;public String tell()return this.teacher;/3.学校 (School)类class School implements TellString school;public School(String school)this.school=schoo
2、l;public String tell()return this.school;package shiyan;public class Printer /* param args*/福建工程学院public static void main(String args) / TODO 自动生成的方法存根Teacher a = new Teacher(“Java教师-唐老师“ );School a1 = new School(“学校-福建工程学院“ );print(a);print(a1);2工厂设计模式开发需求:(1)信用卡分为 VISA, AMERICANEXPRESS, MASTERCARD
3、 三种类型,为每种信用卡写一个类。(2)每个信用卡类都有一个处理 POS 机刷卡的方法 swipeCard_POS()。(3)请使用接口技术和工厂模式实现开发需求。福建工程学院/接口public interface Card public void swipeCard_POS();package shiyan2;import java.util.Scanner;public class Login /* param args*/测试类public static Card getInstance(String type,String id)福建工程学院if(“VISA“.equals(type)
4、card = new VISA(id);if(“AMERICANEXPRESS“.equals(type)card = new AMERICANEXPRESS(id);if(“MASTERCARD“.equals(type);card = new MASTERCARD(id);return card;public static void main(String args) / TODO 自动生成的方法存根Scanner in = new Scanner(System.in);String name,id;System.out.println(“输入信用卡类型:“ );name=in.nextL
5、ine();System.out.println(“输入卡号:“);id = in.nextLine();Card card = getInstance(name, id);card.swipeCard_POS();/3.MASTERCARD类class MASTERCARD implements Card福建工程学院public MASTERCARD(String id) this.id = id;public void swipeCard_POS() System.out.println(“MASTERCARD-“+id+“-by POS!“);/2.AMERICANEXPRESS类cla
6、ss AMERICANEXPRESS implements CardString id;public AMERICANEXPRESS(String id) this.id = id;public void swipeCard_POS()System.out.println(“AMERICANEXPRESS-“+id+“-by POS!“);福建工程学院public VISA(String id) this.id = id;public void swipeCard_POS() System.out.println(“VISA-“+id+“-by POS!“);福建工程学院福建工程学院Strin
7、g name;char sex;double hight;double weight;public int compareTo(Student s)return pareTo(s.id);public Student(String id,String name,char sex,double hight,double weight) this.id=id;this.name=name;this.sex=sex;this.hight=hight;this.weight=weight;public void disp() System.out.println(“学号:“ +id+“ 姓名:“+na
8、me+“ 性别:“+ sex+“ 身高:“ +hight+“ 体重:“+ weight);福建工程学院import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;public class Class String bj;ArrayListstudents;public Class(String bj)this.bj=bj;this.students=new ArrayList();public void disp1()System.out.println(“班级:“ +bj);for(Student s:students)s.disp();