Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming: public class AccountDriver { public static void main(String[]

ID: 3669238 • Letter: J

Question

Java Programming:

public class AccountDriver {
  
   public static void main(String[] args) {
      
      
       Account myAccount = new Account(127892, 2000, 0.2);
       System.out.println(myAccount.toString());
      
       //Add $100 to balance
       myAccount.deposit(100);
       System.out.println(myAccount.toString());
      
       //subtract $400 from balance
       myAccount.withDraw(400);
       System.out.println(myAccount.toString());
      
   }
  
   public String toString() {

String ret = "Account Summary: ";

ret = "Balance: " + balance;

return ret;

   }
}

An int data field named id for the account (default 0) A double data field named balance for the account (default 0) . . A double data field named annuallnerestRate that stores the current interest rate (default 0) A Date data field named dateCreated that stores the date when the account was created. . A no-arg constructor that creates a default account Another constructor that creates an account with the specified values for id balance and annuallnerestRate The accessor and mutator methods for id, balance, and annualInterestRate. The accessor method for dateCreated. A method named getMonthlylnterestRate0 that returns the monthly interest rate ° . . . A method named withDraw0 that withdraws a specified amount from the account. A method named deposit that deposits a specified amount to the account. What to return: Account.java . AccountDriver.java

Explanation / Answer

AccountDriver.java

// class
public class AccountDriver {
   public static void main(String[] args)
   {
       // create object of class Account
        Account myAccount = new Account(127892, 2000, 0.2);
      
       // call function
       myAccount.withdraw(2500);
       myAccount.deposit(3000);
      
       // display result
       System.out.println("The balance of the account is $" +myAccount.getBalance());
       System.out.println("The monthly interest rate is " +myAccount.getMonthlyInterestRate()+ "%");
       System.out.println("The account was created " +myAccount.getDateCreated());
   }

}

Account.java
import java.util.Date;

public class Account {
   // declare variables
   private int id;
   private double balance;
   private double annualInterestRate;
   Date dateCreated;
  
   // constructor
   public Account()
   {
       id = 0101;
       balance = 100;
       annualInterestRate = .15;
       dateCreated = new Date();
   }
  
   // con with parameter
   public Account(int id, double balance, double annualInterestRate)
   {
       this.id = id;
       this.balance = balance;
       this.annualInterestRate = annualInterestRate;
       dateCreated = new Date();
   }
  
   // getting id
   public double getId()
   {
       return id;
   }
  
   // getting balance
   public double getBalance()
   {
       return balance;
   }
  
   //get interest rate
   public double getAnnualInterestRate()
   {
       return annualInterestRate;
   }
  
   // set id
   public void setId(int id)
   {
       this.id = id;
   }
  
   // set balance
   public void setBalance(double balance)
   {
       this.balance = balance;
   }
   public void setAnnualInterestRate(double annualInterestRate)
   {
       this.annualInterestRate = annualInterestRate;
   }
  
   // created date
   public Date getDateCreated()
   {
       return new Date();
   }
  
   public double getMonthlyInterestRate()
   {
       return annualInterestRate/12;
   }
  
   public void withdraw(double balance)
   {
       this.balance -= balance;
   }
  
   public void deposit(double balance)
   {
       this.balance += balance;
   }
}


output

                                                                                                                   
The balance of the account is $2500.0                                                                                                                       
The monthly interest rate is 0.016666666666666666%                                                                                                          
The account was created Thu Feb 18 09:06:54 UTC 2016                                                                                                        

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote