求java源程序编写,谢谢
求java源程序编写,谢谢.编写Java应用程序。首先定义一个描述银行账户的Account类,包括成员变量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询...
求java源程序编写,谢谢.编写Java应用程序。首先定义一个描述银行账户的Account类,包括成员变
量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次,
编写一个主类,在主类中测试Account类的功能。 展开
量“账号”和“存款余额”,成员方法有“存款”、“取款”和“余额查询”。其次,
编写一个主类,在主类中测试Account类的功能。 展开
展开全部
package 临时;
public class Test15 {
public static void main(String[] args) {
Account a = new Account(1, 1000);
a.cunKuan(100);
a.quKuan(1000);
a.quKuan(10000);
System.out.println(a.Query());
}
}
class Account {
private int id;
private double Balance;
public void quKuan(double money) {
if (Balance >= money) {
this.Balance = this.Balance - money;
System.out.println("已取出");
} else {
System.out.println("账户余额不足!无法取款!");
}
}
public void cunKuan(double money) {
this.Balance = this.Balance + money;
System.out.println("已存入");
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double Query() {
return Balance;
}
public void setBalance(double balance) {
Balance = balance;
}
public Account() {
super();
}
public Account(int id, double balance) {
super();
this.id = id;
Balance = balance;
}
}
追问
谢谢,麻烦您了
展开全部
public class Account {
private int accountNo;
private double balance=0;
public Account(int accountNo) {
this.accountNo = accountNo;
}
public void deposit(double n){
balance+=n;
System.out.println("存入:"+n);
System.out.println("当前余额:"+balance);
}
public double getBalance(){
System.out.println("当前余额:"+balance);
return balance;
}
public void draw(double n){
if(n>balance){
System.out.println("余额不足");
return;
}
balance-=n;
System.out.println("取出:"+n);
System.out.println("当前余额:"+balance);
}
public static void main(String[] args) {
Account a = new Account(1);
a.deposit(120);
a.getBalance();
a.draw(51);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询