我需要帮助完成这个代码.. [英] I need help finishing off this code..

查看:56
本文介绍了我需要帮助完成这个代码..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题如下 -

设计一个名为BankAccount的抽象类来保存银行账户的以下数据:

●余额

●本月存款数量

●提款数量

●年利率

●每月服务费

该类应具有以下方法:

*构造函数 - 构造函数应接受余额和年利率的参数。

*存款 - 接受参数的方法对于存款金额。该方法应将参数添加到帐户余额中。它还应该增加持有存款数量的变量。

*取款 - 一种接受退出金额参数的方法。该方法应从余额中减去参数。它还应该增加持有提款数量的变量。

* calcInterest-通过计算账户每月利息来更新余额并将此利息添加到余额的方法。这由以下公式执行:

每月利率ئج(年利率/ 12)每月利息ئج余额*每月利率余额ئج余额ئح每月利息

* monthlyProcess - 一种从平衡中减去每月服务费用的方法,调用calcInterest方法,然后将包含提款数量,存款数量和每月服务费用的变量设置为零。

----接下来,设计一个扩展BankAccount类的SavingsAccount类。 SavingsAccount类应具有状态字段以表示活动或非活动帐户。如果储蓄账户余额低于25美元,则变为无效。 (状态字段可以是布尔变量。)在余额提高到25美元以上之前,不能再提取,此时帐户将再次变为活动状态。储蓄帐户类应具有以下方法:

* withdraw - 一种方法,用于确定帐户在提款前是否处于非活动状态。 (如果帐户未处于活动状态,则不允许提款。)然后通过调用方法的超类版本进行提款。

*存款 - 确定帐户在帐户之前是否处于非活动状态的方法存款。如果该帐户处于非活动状态且存款余额超过25美元,则该帐户将再次变为活动状态。然后通过调用方法的超类版本来进行存款。

* monthlyProcess-在调用超类方法之前,此方法检查提取的数量。如果当月的提款次数超过4次,则每次提款4美元以上的服务费将加到持有月度服务费的超级字段中。 (服务费用后不要忘记查看帐户余额。如果余额低于25美元,帐户将无效。)



这是我的意思到目前为止,我的第一堂课很好,我相信,但第二堂课给我带来了问题。

The question is the following-
Design an abstract class named BankAccount to hold the following data for a bank account:
● Balance
● Number of deposits this month
● Number of withdrawals
● Annual interest rate
● Monthly service charges
The class should have the following methods:
*Constructor-The constructor should accept arguments for the balance and annual interest rate.
*Deposit-A method that accepts an argument for the amount of the deposit. The method should add the argument to the account balance. It should also increment the variable holding the number of deposits.
*Withdrawal-A method that accepts an argument for the amount of the withdrawal. The method should subtract the argument from the balance. It should also increment the variable holding the number of withdrawals.
*calcInterest-A method that updates the balance by calculating the monthly interest earned by the account, and adding this interest to the balance. This is performed by the following formulas:
Monthly Interest Rate ﰀ (Annual Interest Rate/12) Monthly Interest ﰀ Balance * Monthly Interest Rate Balance ﰀ Balance ﰁ Monthly Interest
*monthlyProcess-A method that subtracts the monthly service charges from the bal- ance, calls the calcInterest method, and then sets the variables that hold the number of withdrawals, number of deposits, and monthly service charges to zero.
----Next, design a SavingsAccount class that extends the BankAccount class. The SavingsAccount class should have a status field to represent an active or inactive account. If the balance of a savings account falls below $25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals can be made until the balance is raised above $25, at which time the account becomes active again. The savings account class should have the following methods:
*withdraw-A method that determines whether the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method.
*deposit-A method that determines whether the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. The deposit is then made by calling the superclass version of the method.
*monthlyProcess-Before the superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass field that holds the monthly ser- vice charges. (Don’t forget to check the account balance after the service charge is taken. If the balance falls below $25, the account becomes inactive.)

Here is what I have so far, my first class is fine I believe but the 2nd is giving me problems.

public class BankAccount
{
    //declase class fields    
    private double balance;
    private double deposit;
    private double withdrawal;
    private double annualRate;
    private double monthlyFee;
    private double monthlyInterest;
    
    //constructor
    public BankAccount(double myBalance, double myAnnualRate)
    {
        //initiliaze class fields
        balance = myBalance;
        annualRate = myAnnualRate;
        deposit = 0;
        withdrawal = 0;
        monthlyFee = 0;
    }
    
    //class methods
    public double getBalance()
    {
        return balance;
    }
    
    public void setBalance(double myBalance)
    {
        balance = myBalance;
    }
    
    public double getDeposit()
    {
        return deposit;
    }
    
    public void setDeposits(double myDeposit)
    {
        balance = myDeposit;
        deposit += 1;
    }
    
    public double getWithdrawal()
    {
        return withdrawal;
    }
    
    public void setWithdrawal(double myAmount)
    {
        double amount = myAmount;
        balance = balance - myAmount;
        withdrawal += 1;
    }
    
    public double getAnnualRate()
    {
        return annualRate;
    }
    
    public double calcInterest()
    {
        double monthlyRate;
        monthlyRate = (annualRate/12);
        monthlyInterest = balance * monthlyInterest;
        balance = balance + monthlyRate;
        return balance;
    }
    
    public String getMonthlyProcess()
    {
        calcInterest();
        withdrawal = 0;
        deposit = 0;
        monthlyFee = 0;
        return "Monthly Process: " + balance;
    }
}



&


&

public class SavingsAccount extends BankAccount
{
    public int minAmount;
    private double minAmout;
    private int numberOfWithdrawals;
    
    public boolean withdraw(double amount)
    {
     if (getBalance() >= amount + minAmount)
     {
         super.withdraw(amount);
         return true;
        }
        else return false;
    }
    
    public SavingsAccount()
    {
        balance = 0;
        numberOfwithdrawals = 0;
    }
    
    public void withdraw (int amount)
    {
        double tempBalance;
                tempBalance = balance - withdrawMoney;
            
                //checks to make sure you have enough money before calculations are done
                if (tempBalance < 25) {
                    System.out.println ("Insufficient funds! You only have $" + balance + " dollars" );
            }
            
                else {
                    balance -= withdrawMoney;
      
    }
}
    
    public void resetNumOfWithdrawals ()
    {
        
    }
}



错误是super.withdraw(金额)说无法找到退出方法(双重)和可能的错误,我做了大部分工作但是很难完成,任何帮助非常感谢你。


The error is super.withdraw(amount) says can not find the method withdraw(double) and possible errors under that, I did most of the work but am struggling to complete, any help will be great thank you.

推荐答案

25,它变得无效。 (状态字段可以是布尔变量。)在将余额提高到
25, it becomes inactive. (The status field could be a boolean variable.) No more withdrawals can be made until the balance is raised above


25之后,不能再进行提款,此时帐户将再次变为活动状态。储蓄帐户类应具有以下方法:

* withdraw - 一种方法,用于确定帐户在提款前是否处于非活动状态。 (如果帐户未处于活动状态,则不允许提款。)然后通过调用方法的超类版本进行提款。

*存款 - 确定帐户在帐户之前是否处于非活动状态的方法存款。如果帐户处于非活动状态且存款余额高于
25, at which time the account becomes active again. The savings account class should have the following methods:
*withdraw-A method that determines whether the account is inactive before a withdrawal is made. (No withdrawal will be allowed if the account is not active.) A withdrawal is then made by calling the superclass version of the method.
*deposit-A method that determines whether the account is inactive before a deposit is made. If the account is inactive and the deposit brings the balance above


25,则该帐户将再次变为活动状态。然后通过调用方法的超类版本来进行存款。

* monthlyProcess-在调用超类方法之前,此方法检查提取的数量。如果当月的提款数量超过4,则服务费为
25, the account becomes active again. The deposit is then made by calling the superclass version of the method.
*monthlyProcess-Before the superclass method is called, this method checks the number of withdrawals. If the number of withdrawals for the month is more than 4, a service charge of


这篇关于我需要帮助完成这个代码..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆