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

Review Data type class, Inheritance and Polymorphism in JAVA UML OF CLASS ACCOUN

ID: 3745121 • Letter: R

Question

Review Data type class, Inheritance and Polymorphism in JAVA

UML OF CLASS ACCOUNT

PART1-Requi Create a project named FA2018 LAB2PART1 yourLastName Then add a data type class named Account yourLastName and a driver class named BankService yourLastName DATA TYPE CLASS: Provide UML and the code of data type class Account yourLastName to hold the information of an account with account number (String), customer name (String), address, balance (double) with no-argument constructor parameter constructor LAB 1 Also, define some methods to handle the tasks: open account, check current balance, deposit, withdraw, and print monthly statement OPEN ACCOUNT display the output: (for example with accout last name is Le, accout first name is Liem, account number is 1567794657, and balance is 500) Account Name: Account Number New Account balance: Le, Liem 1567794657 500.0 CHECK BALANCE Display the output as belows: (for example current balance is 500) Account Name: Account Number: Current Balance: Le, Liem 1567794657 500.0 DEPOSIT Calculate the new balnce then display output (if deposit amount is 200) Account Name: Account Number: Deposit amount: New Balance: Le, Liem 1567794657 200.0 00.0 WITHDRAW Calculate new balance then display the message (for example withdraw amount is 300) Account Name: Account Number: Withdraw amount: Le, Liem 1567794657 300.0

Explanation / Answer

Datatype Class:

file 1: Account_yourname.java file

public class Account_Richa{

private BankAccount[] accounts; // contains all the bank accounts in this bank
private int numOfAccounts; // count of the number of bank accounts in this bank

//Constructor: A new Bank object initially doesnt contain any accounts.
public Account_Richa() {
accounts = new BankAccount[100];
numOfAccounts = 0;
}

// Creates a new bank account using the customer name and the opening balance given as parameters
// and returns the account number of this new account. It also adds this account into the account list
// of the Bank calling object.
public int openNewAccount(String customerName,double balance) {

BankAccount b = new BankAccount(customerName, balance);
accounts[numOfAccounts] = b;
numOfAccounts++;
return b.getAccountNum();
}

// Withdraws the given amount from the account whose account number is given. If the account is
// not available in the bank, prints a message.
public void withdrawFrom(int accountNum, double amount) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
accounts[i].withdraw(amount);
System.out.println("Amount withdrawn successfully");
System.out.println(accounts[i].getAccountInfo());
return;
}
}
System.out.println("Account number not found.");
}

// Deposits the given amount to the account whose account number is given. If the account is
//not available in the bank, prints a message.
public void depositTo(int accountNum, double amount) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
accounts[i].deposit(amount);
System.out.println("Amount deposited successfully");
System.out.println(accounts[i].getAccountInfo());
return;
}
}
System.out.println("Account number not found.");
}

// Prints the account number, the customer name and the balance of the bank account whose
// account number is given. If the account is not available at the bank, it should print a message.
public void printMonthlyStatements(int accountNum) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
System.out.println(accounts[i].getAccountInfo());
return;
}
}
System.out.println("Account number not found.");
}

public void printCurrentBalance(int accountNum) {
for (int i =0; i<numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum() ) {
System.out.println(accounts[i].getAccountInfo());
  
return;
}
}
System.out.println("Account number not found.");
}


}

final class BankAccount{

private int accountNumber;
private String customerName;
private double balance;
private double[] transactions;
  
private int numOfTransactions;
private static int noOfAccounts=0;

public String getAccountInfo(){
return "Account number: " + accountNumber + " Account Name: " + customerName + " Balance:" + balance +" ";
}

  

public BankAccount(String abc, double xyz){
customerName = abc;
balance = xyz;
noOfAccounts ++;
accountNumber = noOfAccounts;
transactions = new double[100];
  
transactions[0] = balance;

numOfTransactions = 1;
}

public int getAccountNum(){
return accountNumber;
}

public int getNumberOfTransactions() {
return numOfTransactions;
}

public void deposit(double amt){

if (amt<=0) {
System.out.println("Amount to be deposited should be positive");
} else {
balance = balance + amt;
transactions[numOfTransactions] = amt;

numOfTransactions++;
}
}
public void withdraw(double amt)
{
if (amt<=0){
System.out.println("Amount to be withdrawn should be greater than 0");
}
else
{
if (balance < amt) {
System.out.println("Insufficient balance");
} else {
balance = balance - amt;
transactions[numOfTransactions] = amt;
  
numOfTransactions++;
}
}
}

}//end of class

file2: BankService_yourname.java

import java.util.Scanner;

public class BankService_Richa {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

Account_Richa myBank = new Account_Richa();

int userchoice = 2;

do {

//display menu to user and ask to select his choice

  

System.out.println();

System.out.println("MAIN MENU");

System.out.println("1. Open new Account");

System.out.println("2. Check current balance");

System.out.println("3. Deposit");

  

System.out.println("4. Withdraw");

  

System.out.println("5. Print Monthly Statements");

  

System.out.print("0. Exit ");

System.out.println();

System.out.print("Enter choice [1-5]: or 0 to exit");

userchoice = in.nextInt();

switch (userchoice) {

case 1: System.out.println("Enter the customer Name : ");

String customerName=in.next();

System.out.println("Enter the opening balance");

double balance = in.nextDouble();

System.out.println("Account created. With Account Number: " + myBank.openNewAccount(customerName, balance));

break;

  

case 2: System.out.println("Enter the account number");

int accountNumb=in.nextInt();  

myBank.printCurrentBalance(accountNumb);

break;

case 3: System.out.println("Enter the account number");

int accountNumber=in.nextInt();

System.out.println("Enter the deposit amount");

double deptamt = in.nextDouble();

myBank.depositTo(accountNumber, deptamt);

break;

case 4: System.out.println("Enter the account number");

int accountNumber1 = in.nextInt();

System.out.println("Enter the withdraw amount");

double witamt = in.nextDouble();

myBank.withdrawFrom(accountNumber1, witamt);

break;

case 5: System.out.println("Enter the account number");

int accnum = in.nextInt();

myBank.printMonthlyStatements(accnum);

break;

  

case 0:

  

System.out.println("Thank you. The application is terminating ....");

  

break;

}

}

while (userchoice != '6');

}

}

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