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

Name your source code as .cpp (replace the text with with your last name and fir

ID: 3807762 • Letter: N

Question

Name your source code as .cpp (replace the text with with your last name and first name, in that order) and upload to blackboard. The goal of this assignment is to design and implement classes. We will continue the lesson from the 2/27 lecture on the banking model. Write a program that implements a class model for storing and managing the following data: Test Data: Create a customer using your name and address. Create two accounts for yourself, a Checking and a Savings. Start with a $100 Credit balance in each account. Fill in the other required data as you like (date opened, time stamp). The customer should be able to perform the following actions: Customer: Get the current balance of funds in a specific account identified by the account ID value. Get the total amount of funds across ALL accounts Add money to an account specified by the ID Retrieve money from an account specified by an ID Once you have built your Class Model, write your program to implement your class by outputting to standard output the following transactions: Get balance info for your checking account. Add $10 to both checking and savings account. Retrieve $50 from your checking account Get the total available balance you now have in both accounts.

Explanation / Answer

public class Transaction {

private int transactionId;
private String timeStamp;
private float amount;
private TransactionType type;

public int getTransactionId() {
  return transactionId;
}

public void setTransactionId(int transactionId) {
  this.transactionId = transactionId;
}

public String getTimeStamp() {
  return timeStamp;
}

public void setTimeStamp(String timeStamp) {
  this.timeStamp = timeStamp;
}

public float getAmount() {
  return amount;
}

public void setAmount(float amount) {
  this.amount = amount;
}

public TransactionType getType() {
  return type;
}

public void setType(TransactionType credit) {
  this.type = credit;
}

}

public class Account {
private int accountID;
private String name;
private String dateOpened;
private Transaction[] transaction;

public int getAccountID() {
  return accountID;
}

public void setAccountID(int accountID) {
  this.accountID = accountID;
}

public String getName() {
  return name;
}

public void setName(String name) {
  this.name = name;
}

public String getDateOpened() {
  return dateOpened;
}

public void setDateOpened(String dateOpened) {
  this.dateOpened = dateOpened;
}

public Transaction[] getTransaction() {
  return transaction;
}

public void setTransaction(Transaction[] transaction) {
  this.transaction = transaction;
}

}

public class Customer {
private int customerID;
private String customerName;
private String customerAddress;
private Account[] account;

public int getCustomerID() {
  return customerID;
}

public void setCustomerID(int customerID) {
  this.customerID = customerID;
}

public String getCustomerName() {
  return customerName;
}

public void setCustomerName(String customerName) {
  this.customerName = customerName;
}

public String getCustomerAddress() {
  return customerAddress;
}

public void setCustomerAddress(String customerAddress) {
  this.customerAddress = customerAddress;
}

public Account[] getAccount() {
  return account;
}

public void setAccount(Account[] account) {
  this.account = account;
}

// Get Current Balance of a specific account
public float getCurrBalofAccById(int accountID) {
  float balance = 0.00F;

  for (int i = 0; i < this.account.length; i++) {
   if (this.account[i].getAccountID() == accountID) {
    Transaction tr[] = this.account[i].getTransaction();
    for (int j = 0; j < tr.length; j++) {
     if (TransactionType.CREDIT == (tr[j].getType())) {
      balance = balance + tr[j].getAmount();
     } else if (TransactionType.DEBIT == (tr[j].getType())) {
      balance = balance - tr[j].getAmount();
     }
    }
    break;
   }
  }
  return balance;
}

// Get total balance in all accounts
public float getTotalBalance() {
  float balance = 0.00F;
  for (int i = 0; i < this.account.length; i++) {
   Transaction tr[] = this.account[i].getTransaction();
   for (int j = 0; j < tr.length; j++) {
    if (TransactionType.CREDIT == (tr[j].getType())) {
     balance = balance + tr[j].getAmount();
    } else if (TransactionType.DEBIT == (tr[j].getType())) {
     balance = balance - tr[j].getAmount();
    }
   }

  }
  return balance;
}

public void addMoneytoAccount(int accountId, float money) {
  for (int i = 0; i < this.account.length; i++) {
   if (this.account[i].getAccountID() == accountId) {
    Transaction tr = new Transaction();
    tr.setAmount(money);
    tr.setTimeStamp(new java.util.Date().toString());
    tr.setType(TransactionType.CREDIT);
    Transaction trSet[] = this.account[i].getTransaction();
    Transaction newTrSet[] = new Transaction[trSet.length + 1];
    for (int k = 0; k < trSet.length + 1; k++) {
     if (k == trSet.length) {
      newTrSet[k] = tr;
     } else {
      newTrSet[k] = trSet[k];
     }
    }
    this.account[i].setTransaction(newTrSet);
    break;
   }
  }

}

public void retrieveMoneyFromAccount(int accountId, float money) {
  for (int i = 0; i < this.account.length; i++) {
   if (this.account[i].getAccountID() == accountId) {
    Transaction tr = new Transaction();
    tr.setAmount(money);
    tr.setTimeStamp(new java.util.Date().toString());
    tr.setType(TransactionType.DEBIT);
    Transaction trSet[] = this.account[i].getTransaction();
    Transaction newTrSet[] = new Transaction[trSet.length + 1];
    for (int k = 0; k < trSet.length + 1; k++) {
     if (k == trSet.length) {
      newTrSet[k] = tr;
     } else {
      newTrSet[k] = trSet[k];
     }
    }
    this.account[i].setTransaction(newTrSet);
    break;
   }
  }
}
}

public class Demo {
public static void main(String[] args) {
  Customer c = new Customer();
  c.setCustomerID(1);
  c.setCustomerName("Aditya");
  c.setCustomerAddress("IND");

  Account acc = new Account();
  acc.setAccountID(1);
  acc.setDateOpened(new java.util.Date().toString());
  acc.setName("Aditya");

  Account acc2 = new Account();
  acc2.setAccountID(2);
  acc.setDateOpened(new java.util.Date().toString());
  acc.setName("Aditya");

  Transaction tx = new Transaction();
  tx.setAmount(100.00F);
  tx.setTransactionId(1);
  tx.setType(TransactionType.CREDIT);
  tx.setTimeStamp(new java.util.Date().toString());

  Transaction txarr[] = new Transaction[1];
  txarr[0] = tx;
  acc.setTransaction(txarr);
  acc2.setTransaction(txarr);

  Account[] accArray = new Account[2];
  accArray[0] = acc;
  accArray[1] = acc2;

  c.setAccount(accArray);

  System.out.println(c.getTotalBalance());
  System.out.println(c.getCurrBalofAccById(1));
  System.out.println(c.getCurrBalofAccById(2));
  c.addMoneytoAccount(1, 500.25F);
  c.addMoneytoAccount(2, 200.00F);
  System.out.println(c.getTotalBalance());
  System.out.println(c.getCurrBalofAccById(1));
  System.out.println(c.getCurrBalofAccById(2));
  c.retrieveMoneyFromAccount(1, 0.25F);
  System.out.println(c.getCurrBalofAccById(1));

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote