题目:编写一个模拟电信收费的应用程序。
要求:1.定义一个抽象类Telephone来储存电话的公共数据,属性包括电话号码、开通的服务(本地,国内,国际等)、是否停机和余额;方法包括各种getter和setter方法,按照不同方式收费,余额不足是停机处理。
2.利用重载技术定义一个移动电话类(FiexdTelephone类、此类继承Telephone类)。该类默认开通本地、国内、国际长途业务。
3.定义移动电话类(Mobliephone类继承Telephone类)、重载收费方法,使之能按照优惠时段(时段自行定义)收费。该类默认开通本地通话业务。
下面是我自己编的程序:
package mypackage;
public class Telephone {
private String num;
private boolean local;
private boolean country;
private boolean foregin;
private boolean tingji;
private float money;
public Telephone(){
}
public Telephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money)
{
this.num=num;
this.local=local;
this.country=country;
this.foregin=foregin;
this.tingji=tingji;
this.money=money;
}
public boolean isCountry() {
return country;
}
public boolean isForegin() {
return foregin;
}
public boolean isLocal() {
return local;
}
public float getMoney() {
return money;
}
public String getNum() {
return num;
}
public boolean isTingji() {
return tingji;
}
public void setCountry(boolean country) {
this.country = country;
}
public void setForegin(boolean foregin) {
this.foregin = foregin;
}
public void setLocal(boolean local) {
this.local = local;
}
public void setMoney(float money) {
this.money = money;
}
public void setNum(String num) {
this.num = num;
}
public void setTingji(boolean tingji) {
this.tingji = tingji;
}
public void Charge()
{
float minute=0;
float fee=0;
if(this.local==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(this.country==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(this.foregin==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(fee==0||fee<0)
{
System.out.println("电话已欠费停机!");
}
}
class FixedTelephone extends Telephone
{
void FixeTelephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money){
super.num=num;
super.local=local;
super.country=country;
super.foregin=foregin;
super.tingji=tingji;
super.money=money;
super.country=true;
super.foregin=true;
super.local=true;
System.out.println("本机已开通本地、国内、国际通话业务。");
}
}
class Moblilephone
{
public void Telephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money)
{
local=true;
country=false;
foregin=false;
System.out.println("你的手机只开通了本地通话业务。");
System.out.println("你在早8点到晚8点按照优惠时段收费。");
//int time=0;
float yuan_minute1=0.25f;
float yuan_minute2=0.15f;
float minute=0;
float fee=0;
int time=0;
if(time>8&&time<20)
{
fee=money-minute*yuan_minute1;
}
else
{
fee=money-minute*yuan_minute2;
}
if(fee==0||fee<0)
{
System.out.println("你的手机已经欠费停机。");
}
}
}
public static void main(String[] args)
{
Telephone a=null; Telephone b=null;
a=new Telephone("3939601",false,true,true,false,100);
System.out.println("3939601开通了国内、国际通话业务,没有停机,话费余额为100元");
a.Charge();
b=new Telephone("1340067526",true,false,false,false,200);
// b.Telephone("1340067526",true,false,false,false,200);
}
}
大家帮忙改改,完善一下,谢谢了!
要求:1.定义一个抽象类Telephone来储存电话的公共数据,属性包括电话号码、开通的服务(本地,国内,国际等)、是否停机和余额;方法包括各种getter和setter方法,按照不同方式收费,余额不足是停机处理。
2.利用重载技术定义一个移动电话类(FiexdTelephone类、此类继承Telephone类)。该类默认开通本地、国内、国际长途业务。
3.定义移动电话类(Mobliephone类继承Telephone类)、重载收费方法,使之能按照优惠时段(时段自行定义)收费。该类默认开通本地通话业务。
下面是我自己编的程序:
package mypackage;
public class Telephone {
private String num;
private boolean local;
private boolean country;
private boolean foregin;
private boolean tingji;
private float money;
public Telephone(){
}
public Telephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money)
{
this.num=num;
this.local=local;
this.country=country;
this.foregin=foregin;
this.tingji=tingji;
this.money=money;
}
public boolean isCountry() {
return country;
}
public boolean isForegin() {
return foregin;
}
public boolean isLocal() {
return local;
}
public float getMoney() {
return money;
}
public String getNum() {
return num;
}
public boolean isTingji() {
return tingji;
}
public void setCountry(boolean country) {
this.country = country;
}
public void setForegin(boolean foregin) {
this.foregin = foregin;
}
public void setLocal(boolean local) {
this.local = local;
}
public void setMoney(float money) {
this.money = money;
}
public void setNum(String num) {
this.num = num;
}
public void setTingji(boolean tingji) {
this.tingji = tingji;
}
public void Charge()
{
float minute=0;
float fee=0;
if(this.local==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(this.country==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(this.foregin==true)
{
float yuan_minute=0;
fee=this.money-minute*yuan_minute;
}
if(fee==0||fee<0)
{
System.out.println("电话已欠费停机!");
}
}
class FixedTelephone extends Telephone
{
void FixeTelephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money){
super.num=num;
super.local=local;
super.country=country;
super.foregin=foregin;
super.tingji=tingji;
super.money=money;
super.country=true;
super.foregin=true;
super.local=true;
System.out.println("本机已开通本地、国内、国际通话业务。");
}
}
class Moblilephone
{
public void Telephone(String num,boolean local,boolean country,boolean foregin,boolean tingji,float money)
{
local=true;
country=false;
foregin=false;
System.out.println("你的手机只开通了本地通话业务。");
System.out.println("你在早8点到晚8点按照优惠时段收费。");
//int time=0;
float yuan_minute1=0.25f;
float yuan_minute2=0.15f;
float minute=0;
float fee=0;
int time=0;
if(time>8&&time<20)
{
fee=money-minute*yuan_minute1;
}
else
{
fee=money-minute*yuan_minute2;
}
if(fee==0||fee<0)
{
System.out.println("你的手机已经欠费停机。");
}
}
}
public static void main(String[] args)
{
Telephone a=null; Telephone b=null;
a=new Telephone("3939601",false,true,true,false,100);
System.out.println("3939601开通了国内、国际通话业务,没有停机,话费余额为100元");
a.Charge();
b=new Telephone("1340067526",true,false,false,false,200);
// b.Telephone("1340067526",true,false,false,false,200);
}
}
大家帮忙改改,完善一下,谢谢了!
