大家好,所以我想弄清楚如何让这个代码建立一个银行帐户,但我只能得到零,以获得余额的答案,所有这些,你能帮助我吗?如果你想知道我不允许输入。
包运动12;
public class exercise12 {
public static void main(String[] args) {
Account myaccount = new Account(0, 0, 0, 0);
System.out.println("my initial balance is " + myaccount.getBalance());
System.out.println("depositing 32.19");
myaccount.deposit(32.19);
System.out.println("now my balance is " + myaccount.getBalance());
System.out.println("withdrawing 90.00");
myaccount.withdraw(90.00);
System.out.println("now my balance is " + myaccount.getBalance());
System.out.println("withdrawing 10.00");
myaccount.withdraw(10.00);
System.out.println("now my balance is " + myaccount.getBalance());
}
}
class Account {
public Account (double a, double b, double c, double d) {
deposit = a;
withdraw = b;
account = c;
Balance = d;
}
public void deposit(double d) {
// TODO Auto-generated method stub
}
Double Balance;
Double withdraw;
Double deposit;
Double account;
public void setmoney(double Balance, double withdraw, double deposit, double account){
setBalance(Balance);
setwithdraw(withdraw);
setdeposit(deposit);
setaccount(account);
}
public double getdeposit() {
return deposit;
}
public double withdraw(double d) {
return withdraw;
}
public double getaccount() {
return account;
}
public double getBalance() {
Balance = account - withdraw + deposit;
return Balance;
}
public void setaccount(double accountmoney) {
}
public void setdeposit(double depositmoney) {
}
public void setwithdraw(double withdrawmoney) {
}
public void setBalance(double balancemoney) {
}
}
答案 0 :(得分:1)
您的deposit()
和withdraw()
方法不会更改帐户中的余额。实际上,它们不会对Account
对象中的任何变量进行任何更改。
deposit
和withdraw
。deposit()
方法应将存入的金额添加到余额变量中。withdraw()
方法应从余额变量中扣除已提取的金额。例如:
class Account {
Double balance;
Double account;
public Account (final double accountNumber, final double initialBalance) {
account = accountNumber;
balance = initalBalance;
}
public void deposit(final double amount) {
balance += amount;
}
public double withdraw(final double amount) {
balance -= amount;
return balance;
}
public double getAccount() {
return account;
}
public double getBalance() {
return balance;
}
}