package 继承;public class Example5_19{public static void main(String[] args) {Telephone tel;tel = new Telephone("步步高","84259588",80);tel.setRate(0.3);tel.setDialledTime(100);tel.display();tel.callCost();tel.recharge(10);Mobilephone mobile;mobile=new Mobilephone("Nokia","13007091010",50,"CDMA");mobile.setRate(0.4);mobile.setReceivedTime(120);mobile.display();mobile.callCost();mobile.recharge(100);}}class Telephone{private String brand;private String number;private double dialledTime;private double rate;double balance;public Telephone(String brand, String number, double balance){this.brand = brand;this.number = number;this.balance = balance;}public String getBrand(){return brand;}public void setBrand(String brand){this.brand = brand;}public String getNumber(){return number;}public void setNumber(String number){this.number = number;}public double getDialledTime(){return dialledTime;}public void setDialledTime(double dialledTime){this.dialledTime = dialledTime;}public double getRate(){return rate;}public void setRate(double rate){this.rate = rate;}public double getBalance(){return balance;}public void recharge(double cost){balance = balance + cost;System.out.println("冲值后的余额:" + balance);}public void callCost(){double callcost = dialledTime * rate;balance = balance - callcost;System.out.println("话费:" + callcost);System.out.println("余额:" + balance);}public void display(){System.out.println("电话品牌:" + brand + "电话号码:" + number);System.out.println("通话时间:" + dialledTime + "费率:" + rate);}}class Mobilephone extends Telephone {private String network;private double callTime;private double receivedTime;public String getNetwork() {return network;}public void setNetwork(String network) {this.network = network;}public double getCallTime() {return callTime;}public void setCallTime(double callTime) {this.callTime = callTime;}public double getReceivedTime() {return receivedTime;}public void setReceivedTime(double receivedTime) {this.receivedTime = receivedTime;}public Mobilephone(String brand,String num,double balance){super(brand,num,balance);}public Mobilephone(String brand,String num,double balance,String network) {super(brand,num,balance);this.network = network;}public void callCost(){double callcost = (this.callTime + 0.5 * this.receivedTime)* this.getRate();balance = balance - callcost;System.out.println("话费:" + callcost);System.out.println("余额:" + balance);}public void display() {System.out.println("电话品牌:" + getBrand()+ "电话号码:" + getNumber() + "网络:"+ network);System.out.println("主叫时间:" + callTime+ "被叫时间:" + receivedTime + "费率:"+ getRate());}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。