我如何在另一个不将输入作为其签名(Java)一部分的方法中使用一个方法的返回值

问题描述 投票:-1回答:1

我有这种方法可以返还存款金额

public double take_deposit_amount_into_checking_account() throws InputMismatchException {
    System.out.println("Enter the amount to be depsosited in the format XX:YY");
    Scanner sc = new Scanner(System.in);
    double deposit_amount = sc.nextDouble();
    System.out.println("You have deposited " + deposit_amount + " into your checkings account ");
    user_option(); // call user option
    return deposit_amount;

}

我有一个secound方法(请参见下文),该方法不将输入作为其签名的一部分,但是将利用上述take_deposit_amount_into_checking_account()的返回值。

在完成初始化后,

双倍存款金额= take_deposit_amount_into_checking_account();

public double withdrawl_from_checking() throws InputMismatchException {
    System.out.println("Enter the amount you wish to deposit");
    Scanner sc = new Scanner(System.in);
    double withdrawl_amount = sc.nextDouble();
    double depositAmount = deposit_amount;
    double balance_after_withdrawal = 0;
    if (withdrawl_amount > 0.0 && withdrawl_amount >= depositAmount) {
        balance_after_withdrawal = depositAmount - withdrawl_amount;
        System.out.println(" You have made a withdrawal in the amount of " + withdrawl_amount
                + " You balance is now " + balance_after_withdrawal);

    } else if (withdrawl_amount > depositAmount) {
        System.out.println(" Insifficient funds: withdrwal amount is greater than current balance");

    }
    return balance_after_withdrawal;

}

我仍然无法成功将deposit_amount的实际值传递给double withdrawl_from_checking()

我不知道第二种方法中我的第一种方法还可以使用返回值。

java parameter-passing
1个回答
0
投票

我没有确切地知道您要做什么,但以下是我的初步发现

© www.soinside.com 2019 - 2024. All rights reserved.