1小时求答案。编写一个完整的Java Application 程序。包含类Acount、类CheckingAccount、类AcountTest

(1)编写一个类Account表示账户对象,包含以下成员
①属性:
1)id:私有,int型,表示账户编号;
2)balance:私有,double型,表示账户余额;
②方法:
1)Account(), 构造方法,id和balance都初始化为0;
2)Account(int id,double balance),构造方法,用参数设置账户编号和余额;
3)void setBalance(double balance):修改账户金额
4)double getBalance():返回账户金额
5)boolean withDraw(double money):从账户提取特定数额,如果余额不足,返回false;否则,修改余额,返回true;
6)void deposit(double money):向账户存储特定数额。
7)public String toString():将把当前账户对象的转换成字符串形式,例如id为123,余额为1000.0,返回字符串"The balance of account 123 is 1000.0"。
(2)编写一个Account类的子类CheckingAccount,表示支票账户对象,包含以下成员
①属性:
1)overdraft:私有,double型,表示透支限定额;
②方法:
1)CheckingAccount(), 构造方法,id、balance和overdraft都初始化为0;
2)CheckingAccount(int id,double balance,double overdraft),构造方法,用参数设置账户编号、余额和透支限定额;
3)boolean withDraw(double money):从账户提取特定数额,如果超出透支限定额,返回false;否则,修改余额,返回true;
(3)编写公共类AcountTest,实现如下功能
1)创建一个账户id为1122、余额为20000、透支额度为10000的支票账户;
2)存款10000
3)取款40000,并显示是否取款成功
4)使用toString方法输出账户信息。
输出格式如下:
WithDraw 40000 successes
The balance of account 1122 is -10000.0

第1个回答  2013-07-01
class Account
{
private int id;
private double balance;
public Account()
{
id=0;
balance=0;
}
public Account(int id,double balance)
{
this.id=id;
this.balance=balance;
}
public void setBalance(double balance)
{
this.balance=balance;
}
public double getBalance()
{
return balance;
}
public int getID()
{
return id;
}
public boolean withDraw(double money)
{
if(money>this.balance)
{
return false;
}
else
{
this.balance-=money;
return true;
}
}
public void deposit(double money)
{
this.balance+=money;
}
public String toString()
{
return "The balance of Account "+this.id+" is " +this.balance;
}
}
public class CheckingAccount extends Account
{
private double overdraft;
public CheckingAccount()
{
super(0,0);
this.overdraft=0;
}
public CheckingAccount(int id,double balance,double overdraft)
{
super(id,balance);
this.overdraft=overdraft;
}
public boolean withDraw(double money)
{
Account of=new Account();
if(of.getBalance()-money>this.overdraft)
{
System.out.println("withDraw is failure");
return false;
}
else
{
of.setBalance(of.getBalance()-money);
System.out.println("withDraw is successful");
return true;
}
}
}
public class AccountTest
{
public static void main(String[] args)
{
Account test=new CheckingAccount(1122,20000,10000);
test.deposit(10000);
CheckingAccount of=new CheckingAccount();
of.withDraw(40000);
System.out.println(test);
}

}
第2个回答  2013-07-01
Withdraw 40000 SUCCSS.
The balance of account 1122 is 0.0

编写book类。包含书籍名称,书号,单价,库存数量等数据成员。
void Book::setbook(string bkname, string aut, int acc){ bookname = bkname;author = aut;account = acc;cout << "书名: " << bookname << endl;cout << "作者: " << author << endl;cout << "月销售量: " << account << endl;Book obj1("C语言程序设计","谭浩强",800),...

相似回答