第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果 else 語句沒有調(diào)用 isServiceCharge() 方法?

如果 else 語句沒有調(diào)用 isServiceCharge() 方法?

冉冉說 2021-10-13 13:58:25
我?guī)缀跬瓿闪诉@個(gè)銀行賬戶程序。我有一個(gè)calculateSavings()方法或calculateCheckings()方法的調(diào)用。如果currentBalance小于要求的minSavingsor minChecking,我有一個(gè)else語句來調(diào)用該isServiceCharge()方法來扣除費(fèi)用。該程序沒有給我錯(cuò)誤,但如果用戶輸入的 acurrentBalance小于minChecking或所需的數(shù)量minSavings,JOptionPane則不會(huì)顯示輸出。輸入仍然有效,但沒有彈出輸出。其他一切都可以正常工作,例如增加利息,但在服務(wù)費(fèi)中扣除費(fèi)用則不然。我怎樣才能解決這個(gè)問題?主班package com.company;import javax.swing.*;public class Main{    public static void main(String[] args)    {        {            BankAccount myBank = new BankAccount();            myBank.calculateNewBalance();        }    }}
查看完整描述

2 回答

?
四季花海

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超5個(gè)贊

這是一個(gè)小問題


如果您看到此功能,您將帳戶類型更改為'Savings' 或 'Checking'。


public void calculateNewBalance()

   {

    if (accountType.equals("S") || accountType.equals("s"))

    {

        accountType = "Savings";

        calculateSavingsBalance();


    } else if (accountType.equals("C") || accountType.equals("c"))

    {

        accountType = "Checking";

        calculateCheckingBalance();

    }



}

然而,您正在將 accountType 與'c' 或 's'進(jìn)行比較


public void isServiceCharge()

{

    if(accountType.equals("s") || accountType.equals("S"))

    {

        double newBalance = currentBalance - 10.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }

    else if(accountType.equals("c") || accountType.equals("C"))

    {

        double newBalance = currentBalance - 25.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }


}

這就是它沒有進(jìn)入任何一個(gè)塊的原因,因此,如果您將條件更改為以下語句


if(accountType.equals("Savings"))


else if(accountType.equals("Checking"))

它會(huì)按您的預(yù)期工作


查看完整回答
反對(duì) 回復(fù) 2021-10-13
?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

你的代碼中實(shí)際發(fā)生了什么,


public void calculateNewBalance()

{

    if (accountType.equals("S") || accountType.equals("s"))

    {

        accountType = "Savings";

        calculateSavingsBalance();


    } else if (accountType.equals("C") || accountType.equals("c"))

    {

        accountType = "Checking";

        calculateCheckingBalance();

    }



}

for s or S accountType = "Savings";


對(duì)于c 或 C accountType = "正在檢查";


但有趣的是在isServiceCharge()方法中


public void isServiceCharge()

{

    if(accountType.equals("s") || accountType.equals("S"))

    {

        double newBalance = currentBalance - 10.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }

    else if(accountType.equals("c") || accountType.equals("C"))

    {

        double newBalance = currentBalance - 25.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }


}

你檢查過


accountType.equals("s") || accountType.equals("S") //for savings

accountType.equals("C") || accountType.equals("c")// for checking

所以上述條件永遠(yuǎn)不會(huì)滿足。


所以解決辦法是:


public void isServiceCharge()

{

    if(accountType.equals("Savings"))

    {

        double newBalance = currentBalance - 10.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }

    else if(accountType.equals("Checking"))

    {

        double newBalance = currentBalance - 25.0;

        JOptionPane.showMessageDialog(null, "Account Number: " + getAccountNumber() + "\nAccount Type: " + getAccountType() + "\nMinimum Balance: $" + getMinSavings()

                + "\nBalance Before Interest and Fees: $" + getCurrentBalance() + "\n\nNew Balance: $" + newBalance);

    }


}


查看完整回答
反對(duì) 回復(fù) 2021-10-13
  • 2 回答
  • 0 關(guān)注
  • 146 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)