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

Using JAVA Create an Account class. The account class should have a type attribu

ID: 3890253 • Letter: U

Question

Using JAVA

Create an Account class. The account class should have a type attribute for “Checking” or “Savings”, use an enum for this. The account class should have a balance attribute. In the constructor it should take a User object and the initial balance. It should maintain a reference to the user class as a property on the class. Give it a method called credit that adds money to the balance and a method called debit which removes money from the balance.

In the NewCustomerServlet, where you create the new customer, also create a savings account object for them with an initial balance of 25.00 and a checking account object with a 0.00 initial balance.

Create an AccountDB class, with an insert method that takes an Account object and persists it in the database. In the NewCustomerServlet, use this AccountDB class to save the Checking and Savings account objects.

Explanation / Answer

NOTE : Save each class or enum into their seperate java files, with the same name as class


public class NewCustomerServlet {
  
   public static void main(String args[]) {
       User newCustomer = new User();
      
       /*
       * Create a savings account with initial balance of 25.0
       */
       Account savingsAccount = new Account(newCustomer, 25.0);
       savingsAccount.accountType = AccountType.SAVINGS;
      
       /*
       * Create a checking account with initial balance of 0.0
       */
       Account checkingAccount = new Account(newCustomer, 0.0);
       checkingAccount.accountType = AccountType.CHECKING;

       /*
       * Write to the database
       */
       AccountDB databaseWriter = new AccountDB();
       databaseWriter.insert(savingsAccount);
       databaseWriter.insert(checkingAccount);
      
   }
}

-------------------------------------------------------------------------------------

/*
* ENUM for account types
*/
public enum AccountType {
    CHECKING,
    SAVINGS,
}

-------------------------------------------------------------------------------------

public class Account {

   protected AccountType accountType;
   protected double balance;
   protected User user;

   public Account(User user, double initialBalance) {
       this.balance = initialBalance;
       this.user = user;
   }

   public void credit(double amount) {
       if (amount > 0) {
           balance += amount;
       }
   }
  
   public void debit(double amount) {
       if (amount >= balance) {
           balance -= amount;
       }
       else {
           System.out.println("Insufficient funds");
       }
   }

   public User getUser() {
       return user;
   }

   public void setUser(User user) {
       this.user = user;
   }

   public AccountType getAccountType() {
       return accountType;
   }

   public void setAccountType(AccountType accountType) {
       this.accountType = accountType;
   }
  
}

-------------------------------------------------------------------------------------

public class User {
   /*
   * Fill up the code of the user class. I assume that you
   * already have it, as there was no mention of anything about it
   */
}

class AccountDB {
  
   public void insert(Account userAccount) {
       /*
       * Write your code for insertion into the database here
       * No information has been provided regarding type or name
       * of database, schemas.
       */
   }
}

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