Question

In: Computer Science

THIS IS JAVA PROGRAMMING Design a class named Account (that contains 1. A private String data...

THIS IS JAVA PROGRAMMING

Design a class named Account (that contains

1. A private String data field named id for the account (default 0).

2. A private double data field named balance for the account (default 0).

3. A private double data field named annualInterestRate that stores the current interest rate (default 0).

4. A private Date data field named dateCreated that stores the date when the account was created.

5. A no-arg constructor that creates a default account.

6. A constructor that creates an account with the specified id and initial balance.

7. The accessor and mutator methods for id, balance, and annualInterestRate.

8. The accessor method for dateCreated.

9. A method named getMonthlyInterestRate() that returns the monthly interest rate.

10. A method named withdraw that withdraws a specified amount from the account and returns a boolean based on sufficient funds.

11. A method named deposit that deposits a specified amount into the account, and returns a boolean

12. A method call toString() that returns a “nicely formatted” string similar to the following:

ID: 1234567

Balance: $53,823.27

InterestRate: 0.036

Date Account Created: 10/23/2018

Draw the UML diagram for the class. Implement the class (write the Java code as specified by the UML diagram). Use the Lab7 test program (attached to dropbox) that creates an Account object with an account ID of 5544, a balance of $45,000.00 and an annual interest rate of 3.6%. Use the withdraw method to withdraw $3,700.00, use the deposit method to deposit $2,200.00 and print the balance, the monthly interest, and the date this account was created. Keep in mind that while this tester has hard-coded values, the Account class should be usable by a full-blown application. As such, refrain from having Account.java print messages or accepting input from the keyboard.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================


===========================================

// Account.java

import java.text.SimpleDateFormat;
import java.util.Date;

public class Account {
   private int id;
   private double balance;
   private double annualInterestRate;
   private Date dateCreated;

   public Account() {
       this.id = 0;
       this.balance = 0;
       this.annualInterestRate = 0;
       this.dateCreated = new Date();
   }

   public Account(int id, double initialBal) {
       this.id = id;
       this.balance = initialBal;
       this.annualInterestRate = 0;
       this.dateCreated = new Date();
   }

   public int getId() {
       return id;
   }

   public void setId(int id) {
       this.id = id;
   }

   public double getBalance() {
       return balance;
   }

   public void setBalance(double balance) {
       this.balance = balance;
   }

   public double getAnnualInterestRate() {
       return annualInterestRate;
   }
   public double getMonthlyInterestRate() {
       return annualInterestRate/1200;
   }
   public void setAnnualInterestRate(double annualInterestRate) {
       this.annualInterestRate = annualInterestRate;
   }

   public double getMonthlyInterest() {
       double interest=balance*(annualInterestRate / 1200);
       this.balance+=interest;
       return interest;
   }

   public void withdraw(double amt) {
       if (amt <= balance) {
           balance -= amt;
       } else {
           System.out.println("** Account balance is low **");
       }
   }

   public void deposit(double amt) {
       balance += amt;
   }

   @Override
   public String toString() {
       System.out.println("\nAccount ID:" + id);
       System.out.printf("Balance:$%.2f\n" , balance);
       System.out.printf("Interest Rate: %.3f\n" , (annualInterestRate/100));
       System.out.println("Date Account Created:" + new SimpleDateFormat("dd/MM/yyyy").format(dateCreated));

       return "";
   }

}

======================================

=============================================

// TestAccount.java

public class TestAccount {
   public static void main(String[] args) {
       Account acc=new Account(5544,45000);
       acc.setAnnualInterestRate(3.6);
       acc.getMonthlyInterest();
       acc.withdraw(3700);
       acc.deposit(2200);
      
       System.out.println(acc);

   }

}

=============================================

=============================================

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

Java - Design a class named Account that contains: A private String data field named accountNumber...
Java - Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account....
Design a class named Account that contains: A private String data field named accountNumber for the...
Design a class named Account that contains: A private String data field named accountNumber for the account (default AC000). A private double data field named balance for the account (default 0). A private double data field named annualIntRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default account. A constructor...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data...
7.3 (The Account class) Design a class named Account that contains: ■ A private int data field named id for the account. ■ A private float data field named balance for the account. ■ A private float data field named annualInterestRate that stores the current interest rate. ■ A constructor that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). ■ The accessor and mutator methods for id, balance, and...
Design a class named Account that contains: A private int data field named id for the...
Design a class named Account that contains: A private int data field named id for the account. A private double data field named balance for the account. A private double data field named annualInterestRate that stores the current interest rate. A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. The accessor and mutator methods for id, balance, and annualInterestRate. A method named getMonthlyInterestRate() that returns the monthly interest rate. A method named withdraw(amount)...
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A...
Put In Java Programming The TicketMachine class: Design a class named TicketMachine that contains: • A double data field named price (for the price of a ticket from this machine). • A double data field named balance (for the amount of money entered by a customer). • A double data field named total (for total amount of money collected by the machine). • A constructor that creates a TicketMachine with all the three fields initialized to some values. • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A...
PUT IN JAVA PROGRAMMING The Stock class: Design a class named Stock that contains: • A string data field named symbol1 for the stock’s symbol. • A string data field named name for the stock’s name. • A double data field named previousClosingPrice that stores the stock price for the previous day. • A double data field named currentPrice that stores the stock price for the current time. • A constructor that creates a stock with the specified symbol and...
PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following...
PUT IN JAVA PROGRAMMING The StockB class: Design a class named StockB that contains the following properties: • Name of company • Number of shares owned • Value of each share • Total value of all shares and the following operations: • Acquire stock in a company • Buy more shares of the same stock • Sell stock • Update the per-share value of a stock • Display information about the holdings • The StockB class should have the proper...
In Java, design a class named MyInteger. The class contains: An int data field named value...
In Java, design a class named MyInteger. The class contains: An int data field named value that stores the int value represented by this object. A constructor that creates a MyInteger object for the specified int A get method that returns the int Methods isEven(), isOdd(), and isPrime() that return true if the value is even, odd, or prime, respectively. Static methods isEven(int), isOdd(int), and isPrime(int) that return true if the specified value is even, odd, or prime, respectively. Static...
Design a class named BankAccount that contains: A private int data field named id for the...
Design a class named BankAccount that contains: A private int data field named id for the account. A private double data field named balance for the account. A constructor that creates an account with the specified id and initial balance. A getBalance() method that shows the balance. A method named withdraw that withdraws a specified amount from the account. Create a subclass of the BankAccount class named ChequingAccount. An overdraftlimit to be 1000 for ChequingAccount . Test your ChequingAccount class...
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/...
Java programming. ** Create Account class include: 1/ private long   accountNumber; 2/ private String firstName; 3/ private String lastName; 4/ private double balance; 5/ public Account(long accountNumber, String firstName, String lastName, double balance); 6/ get/set methods for all attributes. 7/ public boolean deposit(double amount);   • deposit only if amount is greater than 10 but   less than 200, add the deposit   amount   to the   currentbalance. • if deposit is   successful return true,   otherwise return false; 8/ public boolean withdrawal(double amount); •...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT