急求!!!!!!!!

 

代码如下:


public class 电话支付测试 {

	public static void main(String[] args) {
		MobilePhone mobile = new MobilePhone("15374363882", 80, 2, 30, 2);
		Telephone tel = new Telephone("0797-8888888", 50, 2, 15);
		mobile.pay();
		mobile.display();
		System.out.println("-------------------------------------------");
		tel.pay();
		tel.display();
		
	}
}
interface Payable{
	void pay();
}
abstract class Phone{
	String code;
	public Phone(String code) {
		this.code = code;
	}
	abstract void display();
}
class MobilePhone extends Phone implements Payable{
	int time;
	float price;
	float internetFee;
	float messageFee;
	public MobilePhone(String code,int time,float price,float internetFee,float messageFee) {
		super(code);
		this.time = time;
		this.price = price;
		this.internetFee = internetFee;
		this.messageFee = messageFee;
	}
	
	@Override
	void display() {
		System.out.println("网费:¥"+ this.internetFee);
		System.out.println("短信费:¥"+ this.messageFee);
		System.out.println("通话费:¥"+ this.price*time);
	}

	@Override
	public void pay() {
		System.out.println("号码是:"+this.code +",本月费用合计:¥" + (price*time+internetFee+messageFee));
		
	}
}
class Telephone extends Phone implements Payable{
	int time;
	float price;
	float monthFee;
	public Telephone(String code,int time,float price,float monthFee) {
		super(code);
		this.time = time;
		this.price = price;
		this.monthFee = monthFee;
	}
	@Override
	void display() {
		System.out.println("¥月租费:"+ this.monthFee);
		System.out.println("¥通话费:"+ this.price*time);
	}
	@Override
	public void pay() {
		System.out.println("号码是:"+this.code +",本月费用合计:¥" + (price*time+monthFee));
	}
}

 

运行结果:

 

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps: 问答会员年卡【8折】购 ,限时加赠IT实体书,即可 享受50次 有问必答服务,了解详情>>>https://t.csdnimg.cn/RW5m