Question: -JAVA PART1 Requirement - Demo_UnsortedOptimizedArray Create a project named FA2018_LAB3PART1_yourLastName - add a data type class named Account_yourLastName, CheckingAccount_yourLastName and SavingAccount_yourLastName -add data structure class
-JAVA
PART1 Requirement - Demo_UnsortedOptimizedArray Create a project named FA2018_LAB3PART1_yourLastName - add a data type class named Account_yourLastName, CheckingAccount_yourLastNameandSavingAccount_yourLastName -add data structure class named Account_UnsortedOptimizedArray (use the code in the book chapter 2 for your reference) -add driver class named Demo_UnsortedOptimizedArray_yourLastName
Provide the application that allows users can do the following tasks:
Insert One Account
Verify encapsulation of Unsorted Optimized Array
Update an account
Remove an account
Show all accounts
0. Exit
TASK1: INSERT
-Ask for information of one account. It could be checking account or saving account; insert to the data structure, then check if insert successfully display message box: Insert Account success Otherwise display message box Insert Account failed
TASK2: VERIFY ENCAPSULATION -Ask for insert a new account as task1, for example node name account -Modify the service fee (if checking account) or interest rate (if saving account) of account -Fetch the node with the same account number, store the fetched node with the name copy -compare the information just modify between account and copy If the information are the same, display message box: Unsorted Optimized Array is not encapsulated Otherwise display the messageg: Unsorted Optimized Array is encapsulated
TASK3: UPDATE -Ask for insert a new account as task1, for example node name account -Modify the service fee (if checking account) or inerest rate (if saving account) of account
-Updateaccount to the data structure -If update return true, display message box Update successfully Otherwise display message box Update failed
TASK4: REMOVE
-Ask for the account number that you want to remove -Delete that account -If delete returns true display message box: Delete successfully Otherwise display message box: Delete failed
TASK5: SHOW ALL
-show all accounts currently stored in the data structure You should allow users to continue using your program until they want to exit
I need help with my driver class. Here is my codes:
public class Account { public String name; public String accountNumber; public double balance;
//Constructor to set name, account number and balance public Account_Essat(String nm,String accNum,double bal) { name=nm; accountNumber=accNum; balance=bal; }
//Constructor with no arg-parameters public Account() { name=" "; accountNumber=" "; balance=0; }
public void openAccount() { System.out.println("Name is "+ name); System.out.println("Account number "+ accountNumber); System.out.println( "Balance is "+ balance); }
public void checkCurrentBalance() { System.out.println("Account Name: "+ name); System.out.println("Account Number: "+ accountNumber); System.out.println("Current Balance: "+ balance); } public void depositAmount(double amount) { balance = balance + amount; System.out.println("Account Name: "+ name); System.out.println("Account Number: "+ accountNumber); System.out.println("Deposit Amount: "+ amount); System.out.println("New Balance: "+ balance); }
public void withdrawAmount(double amount) { if(balance >= amount) { balance = balance - amount; System.out.println("Account Name: "+ name); System.out.println("Account Number: "+ accountNumber); System.out.println("Withdrawn Amount: "+ amount); System.out.println("New Balance: "+ balance); } else System.out.println("Not enough balance"); }
public void bankStatement() { System.out.println("Account Name: "+ name); System.out.println("Account Number: "+ accountNumber); System.out.println("End Balance: "+ balance); } public Account deepCopy() { Accountclone = new Account(name, accountNumber, balance); return clone; }
public int compareTo(String targetKey) { return(name.compareTo(targetKey)); }
}
public class SavingsAccount extends Account { public double intRate; //Constructor public SavingsAccount(String nm, String accNum, double bal, double intRate ) { super(nm, accNum, bal); intRate = intRate; }
public void openAccount() { System.out.println("Account Type: Savings Account"); super.openAccount(); }
public void checkCurrentBalance() { System.out.println("Account Type: Savings Account"); super.checkCurrentBalance(); }
public void depositAmount(double amount) { System.out.println("Account Type: Savings Account"); super.depositAmount(amount); }
public void withdrawAmount(double amount) { System.out.println("Account Type: Savings Account"); super.withdrawAmount(amount); }
public void calculateInterest() { super.balance = super.balance * intRate * 0.01; }
public void bankStatement() { calculateInterest(); System.out.println("Account Type: Savings Account"); System.out.println("Interest Rate:$" + intRate); super.bankStatement(); } }
public class CheckingAccount extends Account { public double service_Fee;
public CheckingAccount(String nm, String accNum, double bal) { super(nm, accNum, bal); }
public void openAccount() { System.out.println("Account Type: Checking Account"); super.openAccount(); }
public void checkCurrentBalance() { System.out.println("Account Type: Checking Account"); super.checkCurrentBalance(); }
public void depositAmount(double amount) { System.out.println("Account Type: Checking Account"); super.depositAmount(amount); }
public void withdrawAmount(double amount) { System.out.println("Account Type: Checking Account"); super.withdrawAmount(amount); }
public void calculateFee() { super.balance = balance * service_Fee* 0.01; }
public void bankStatement() { calculateFee(); System.out.println("Type: Checking Account"); System.out.println("Service Fee:$" + service_Fee); super.bankStatement(); } }
public class Account_UnsortedOptimizedArray { private int next; private int size; private Account[] data; //Constructor public Account_UnsortedOptimizedArray() { next = 0; size = 100; data = new Account [size]; } public boolean insert(Account newNode) { if(next>= size) return false; data [next] = newNode.deepCopy(); if(data[next] == null) return false; next = next + 1; return true; } public Account fetch(String targetKey) { Account node; Account temp; int i =0; while(i< next && ! (data[i].compareTo(targetKey) == 0)) { i++; } if(i==next) return null; node = data[i].deepCopy(); if(i!=0) { temp = data[i-1]; data[i-1] = data[i]; data[i] = temp; } return node; }//end of fetch method public boolean delete(String targetKey) { int i =0; while(i < next && ! (data[i].compareTo(targetKey)==0)) { i++; } if(i == next) return false; data[i] = data[next-1]; data[next-1] = null; next = next-1; return true; } //end of delete method public boolean update(String targetKey, Account newNode) { if(delete(targetKey) == false) return false; else if(insert(newNode) == false) return false; else return true; } public void showAll() { for(int i = 0; i< next; i++) System.out.println(data[i].toString()); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
