模拟手机和手机卡号

SIM.java

package phone;

public abstract class SIM {
	public abstract void setNumber(String n);
	public abstract String giveNumber();
	public abstract String giveCorpName(); 
	
}

MobileTelephone.java

package phone;

public class MobileTelephone {
	SIM card;
	public void useSIM(SIM card){
		this.card=card;
	}
	public void showMess(){
		System.out.println("使用的卡号是:"+card.giveCorpName()+"提供的");
		System.out.println("手机号码是:"+card.giveNumber());
	}

}


SIMOfChinaMobile.java

package phone;

public class SIMOfChinaMobile extends SIM {
	String number;
	public void setNumber(String n){
		number=n;
	}
	public String giveNumber(){
		return number;
	}
	public String giveCorpName(){
		return "中国移动";
	}

}

SUMOfChianUnicon.java

package phone;

public class SUMOfChianUnicon extends SIM{
	String number;
	public void setNumber(String n){
		number=n;
	}
	public String giveNumber(){
		return number;
	}
	public String giveCorpName(){
		return "中国联通";
	}
	
}

test.java

package phone;

public class test {

	public static void main(String[] args) {
		MobileTelephone telephone=new MobileTelephone();
		SIM sim=new SIMOfChinaMobile();
		sim.setNumber("13863857200");
		telephone.useSIM(sim);
		telephone.showMess();
		sim=new SUMOfChianUnicon();
		sim.setNumber("13097656437");
		telephone.useSIM(sim);
		telephone.showMess();

	}

}

输出结果:

模拟手机和手机卡号_第1张图片


你可能感兴趣的:(模拟手机和手机卡号)