import java.util.*;
abstract class PhoneCard
{double balance;
abstract boolean performDial(); //定义一个抽象方法performDial(),返回值是布尔类型
double getBalance()
{return balance;
}
}
abstract class None_Number_PhoneCard extends PhoneCard
{String phoneSetType;
String getSetType()
{return phoneSetType;
}
}
abstract class Number_PhoneCard extends PhoneCard
{long cardNumber;
int password;
String connectNumber;
boolean connected;
boolean performConnection(long cn,int pw)
{if(cn == cardNumber && pw == password)
{connected = true;
return true;
}
else
return false;
}
}
class IC_Card extends None_Number_PhoneCard
{boolean performDial()
{if(balance>=0.5)
{balance=balance-0.5;
return true;
}
else
{System.out.println("余额不足!请充值...");
return false;
}//重写方法,如果余额>=0.5,则在余额中减去0.5,否则显示余额不足。
}
}
class D201_Card extends Number_PhoneCard
{double additoryFee;
boolean performDial()
{additoryFee=2.0;
if(balance>=0.5+additoryFee)
{balance=balance-(0.5+additoryFee);
return true;
}
else
{System.out.println("余额不足!请充值...");
return false;
}/*重写方法,如果余额>=(0.5 + additoryFee ),则在余额中减去(0.5 + additoryFee),否则显示余额不足。*/
}
}
public class TestExtends
{public static void main(String args[])
{IC_Card ic_Card = new IC_Card();
ic_Card.balance = 50.0;
System.out.println("IC_Card 的余额:"+ic_Card.getBalance());
if(ic_Card.performDial())
System.out.println("拨打电话后的余额"+ ic_Card.balance);
D201_Card d201_Card=new D201_Card();
d201_Card.balance=100.0;
System.out.println("D201_Card 的余额:"+d201_Card.getBalance());
if(d201_Card.performDial())
System.out.println("拨打电话后的余额:"+d201_Card.balance);
}
}
作者在 2008-04-24 19:28:21 发布以下内容