残高から引き出し額を差し引く簡単な銀行口座プログラムを作成しようとしていますが、deptメソッドを呼び出すと、差し引きが行われません。
このプログラムを機能させる方法。deptメソッドを無効にするか、値を返すかがわかりません。
import java.util.Scanner;
public class JavaApplication7 {
public static void main(String[] args) {
Scanner input = new Scanner( System.in );
Account account1 = new Account( 50.0 );
System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() );
double withdrawalAmount;
System.out.print( "Enter withdrawal amount for account1: " );
withdrawalAmount = input.nextDouble();
System.out.printf( "\nsubtracting %.2f from account1 balance\n", withdrawalAmount );
account1.dept(withdrawalAmount);
System.out.printf( "account1 balance: $%.2f\n", account1.getBalance() );
}
}
public class Account {
private double balance; // instance variable that stores the balance
public Account( double initialBalance )
{
if ( initialBalance > 0.0 )
balance = initialBalance;
}
public double dept (double dept1){
dept1=balance-dept1;
return dept1;
}
public double getBalance()
{
return balance;
}
}