如何创建Savingsaccountdemo [英] How Do I Create A Savingsaccountdemo

查看:79
本文介绍了如何创建Savingsaccountdemo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



•余额

•本月存款数量

•提款数量

•年利率

•每月服务费



该类应具有以下方法:



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



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



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



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



每月利率=(年利率/ 12)

每月利息=余额*每月利息费率

余额=余额+每月利息



monthlyProcess:从余额中减去每月服务费的方法,调用calcInterest方法,然后将保留提款数量,存款数量和月服务费用的变量设置为零。







接下来,设计一个扩展BankAccount类的SavingsAccount类。

SavingsAccount类应该有一个状态字段来表示活动或

非活动帐户。如果储蓄账户余额低于25美元,则变为无效。 (状态字段可以是布尔变量。)在余额提高到25美元以上之前,不能再提取任何金额,此时帐户将再次变为活动状态。储蓄帐户类应具有以下方法:



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



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



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

我还需要一个SavingsAccountDemo来处理两个文件谢谢提前为您提供帮助





这是我的储蓄账户演示



< pre lang =cs> public class SavingsAccountDemo
{

public static void main( String [] args)
{

System。 out .println(帐户);
系统。 out .println( 帐户余额$: + account.getBalance());
系统。 out .println( Withdraw : + account.getNumWithdrawals());
系统。 out .println( 存款: + account.getNumDeposits());
account.monthlyProcess();
}
}





  public   class  BankAccount 
{


private double balance = 0 0 ;
private int numDeposits = 0 ;
private double numWithDrawals = 0 ;
private double annualInterestRate = 0 ;
private double MonthlyserviceCharges = 1 ;



// 持有余额和年度利息的构造函数费率
BankAccount( double bal, double intRate)
{
balance = bal;
annualInterestRate = intRate;

}

public void deposit(< span class =code-keyword> double
金额)
{
余额+​​ =金额;
numDeposits ++;

}
public void withDrawal( double amount)
{
余额 - =金额;
numWithDrawals ++;
}

public void calcInterest()
{
double monthlyInterestRate;
double monthlyInterest;

monthlyInterestRate =(annualInterestRate / 12 );
monthlyInterest = balance * monthlyInterestRate;
余额=余额+ monthlyInterest;
}

public void monthlyProcess()
{
余额 - = MonthlyserviceCharges;
calcInterest();
numWithDrawals = 0 ;
numDeposits = 0 ;
MonthlyserviceCharges = 0 ;
}

public double getBalance()
{
返回余额;
}
}





  public   class  SavingsAccount扩展了BankAccount {
private 布尔状态;
public SavingsAccount( double 余额, double annualInterestRate)
{
super();

}
public void withDrawal(金额)
{
如果(余额> = 25
super.withDrawal(amount);
else
系统。 out .println( 您的帐户无效。您的余额需要超过25美元。);
}

public void 存款(金额)
{
如果(余额> = 25
super.deposit(amount);
else
系统。 out .println( 您的帐户无效。您的余额需要超过25美元。);
}

public void monthlyProcess()
{
if (withDrawals > 4
serviceCharge ++;
其他;
}
}







根据我需要的savingsAccount和BankAccount创建一个编译并要求输入余额,存款数量等的演示

解决方案

25,它变为非活动状态。 (状态字段可以是布尔变量。)在余额提高到


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



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



存款:确定的方法在存款之前帐户是否处于非活动状态。如果帐户处于非活动状态且存款余额高于


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



monthlyProcess:在调用超类方法之前,此方法检查提款的数量。如果当月的提款数量超过4,则服务费为


Design a 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.

withdraw: 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 balance, 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 may 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. A 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 service 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.)
And I also need a SavingsAccountDemo to process to two files thanks in advance for ur help


This is my savingsAccountDemo

public class SavingsAccountDemo
{

    public static void main(String[] args)
    {

        System.out.println(account);
        System.out.println("Account Balance $:" + account.getBalance());
        System.out.println("Withdraw:" + account.getNumWithdrawals());
        System.out.println("Deposit:" + account.getNumDeposits());
        account.monthlyProcess();
    }
}



public class BankAccount
  {


  private double balance = 0.0;
   private int numDeposits = 0;
   private double numWithDrawals = 0;
   private double annualInterestRate = 0;
   private double MonthlyserviceCharges = 1;



// The constructor to hold balance and Annual Interest Rate
   BankAccount(double bal, double intRate)
  {
    balance = bal;
    annualInterestRate = intRate;

  }

  public void deposit(double amount )
  {
    balance +=amount;
    numDeposits++;

  }
  public void withDrawal(double amount)
  {
    balance -= amount;
    numWithDrawals++;
  }

  public void calcInterest()
  {
    double monthlyInterestRate;
    double monthlyInterest;

    monthlyInterestRate = (annualInterestRate / 12);
    monthlyInterest = balance * monthlyInterestRate;
    balance = balance + monthlyInterest;
  }

  public void monthlyProcess()
  {
    balance -= MonthlyserviceCharges;
    calcInterest();
    numWithDrawals = 0;
    numDeposits = 0;
    MonthlyserviceCharges = 0;
  }

  public double getBalance()
  {
    return balance;
  }
}



public class SavingsAccount extends BankAccount {
    private boolean status;
        public SavingsAccount(double balance, double annualInterestRate)
{
super();

}
public void withDrawal(double amount)
{
  if(balance >= 25)
    super.withDrawal(amount);
  else
    System.out.println("Your account is inactive. Your balance needs to be over $25." );
}

public void deposit(double amount)
{
 if(balance >= 25)
   super.deposit(amount);
 else
   System.out.println("Your account is inactive. Your balance needs to be over $25." );
}

public void monthlyProcess()
{
  if(withDrawals > 4)
    serviceCharge++;
   else;
}
}




Based on the savingsAccount and BankAccount I need to create a demo that compiles and ask to input the balance,number of deposits,etc

解决方案

25, it becomes inactive. ( The status field could be a boolean variable.) No more withdrawals may 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. A 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


这篇关于如何创建Savingsaccountdemo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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