On my assigment, we suppose to have interest on Checking account, it has interes
ID: 3769033 • Letter: O
Question
On my assigment, we suppose to have interest on Checking account, it has interest rate on 90 days elapses , such as when - ( Less than $1000 = 1%) -( $1001 - $10000 = 2%) and last ( more than $10000 = 3%) this only with the lock out time span for 60 days ( no withdrawal allowed)
--------------------------------------------------------------------------------
BankApp.java
package bankapp;
import java.util.Scanner;
public class BankApp
{
public static void main(String[] args)
{
Scanner s = new Scanner ( System.in);
Bank myBank = new Bank();
//transInfo[0]= "A depsited 30k";
int user_choice = 2;
do
{
// display menu to user
// ask user for his chice and validate it ( make sure it is between 1 and 6)
System.out.println(" WELCOME TO YOUR BANK");
System.out.println(" --------------------");
System.out.println();
System.out.println("1) Open a new bank account");
System.out.println("2) Deposit to a bank account");
System.out.println("3) Withdraw bank account");
System.out.println("4) Print short account information");
System.out.println("5) Print the detailed account information including last transaction");
System.out.println("6) Quit");
System.out.println();
System.out.println(" Enter choice [1-6]: ");
user_choice = s.nextInt();
switch ( user_choice)
{
case 1:
System.out.println("Enter a customer name");
; String cn = s.next();
System.out.println(" Enter an opening balance");
double d = s.nextDouble();
System.out.println(" (1)Saving account. (2) Checking account");
int t = s.nextInt();
System.out.println("Account was created and it has the following number :" + myBank.openNewAccount(cn, d,t));
break;
case 2:
System.out.println("Enter an account number");
int an = s.nextInt();
System.out.println("Enter a deposit amount ");
double da = s.nextDouble();
myBank.depositTo(an, da);
break;
case 3:
System.out.println("Enter an account number");
int acn = s.nextInt();
System.out.println("Enter a withdraw amount ");
double wa = s.nextDouble();
myBank.withdrawFrom(acn, wa);
break;
case 4:
System.out.println("Enter an account number");
int anum = s.nextInt();
myBank.printTransactionInfo(anum);
break;
case 5:
System.out.println("Enter an account number");
anum = s.nextInt();
myBank.printTransactionInfo(anum);
break;
default: System.out.println("Invalid option. Please try again.");
}
}
while ( user_choice !='6');
}
}
Bank.java
package bankapp;
public class Bank {
protected BankAccount[] accounts;
protected int numOfAccounts;
public Bank() {
accounts = new BankAccount[100];
numOfAccounts = 0;
}
public int openNewAccount(String customerName, double openingBalance,
int type) {
BankAccount b;
if (type == 1)
b = new SavingAccount(customerName, openingBalance);
else
b = new CheckingAccount(customerName, openingBalance);
accounts[numOfAccounts] = b;
numOfAccounts++;
return b.getAccountNum();
}
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");
return;
}
}
System.out.println("Account number not found.");
}
public void depositTo(int accountNum, double amount) {
for (int i = 0; i < accounts.length; i++) {
if (accountNum == accounts[i].getAccountNum()) {
accounts[i].deposit(amount);
System.out.println("Amount deposited successfully");
return;
}
}
System.out.println("Account number not found.");
}
public void printAccountInfo(int accountNum) {
for (int i = 0; i < accounts.length; i++) {
if (accountNum == accounts[i].getAccountNum()) {
System.out.println(accounts[i].getAccountInfo());
return;
}
}
System.out.println("Account number no found.");
}
public void printTransactionInfo(int accountNum) {
for (int i = 0; i < accounts.length; i++) {
if (accountNum == accounts[i].getAccountNum()) {
System.out.println(accounts[i].getAccountInfo());
System.out.println("Last transaction: "
+ accounts[i].getTransactionInfo(accounts[i]
.getNumberOfTransactions() - 1));
return;
}
}
System.out.println("Account number not found. ");
}
public void printAccountInfo(int accountNum, int n) {
for (int i = 0; i < numOfAccounts; i++) {
if (accountNum == accounts[i].getAccountNum()) {
System.out.println(accounts[i].getAccountInfo());
System.out.println(accounts[i].getTransactionInfo(n));
return;
}
}
System.out.println("Account number not found. ");
}
}
BankAccount.java
package bankapp;
public class BankAccount extends Bank {
protected int accountNum;
protected String customerName;
protected double balance;
protected double[] transactions;
protected String[] transactionsSummary;
protected int numOfTransactions;
protected static int noOfAccount = 0;
protected String accountType;
public String getAccountInfo() {
return "Account number: " + accountNum + " Customer Name: "
+ customerName + " Balance:" + balance + " ";
}
public String getTransactionInfo(int n) {
String transaction = transactionsSummary[n];
if (transaction == null) {
return "No transaction exists with that number. ";
} else {
return transaction;
}
}
public BankAccount(String abc, double xyz) {
customerName = abc;
balance = xyz;
noOfAccount++;
accountNum = noOfAccount;
transactions = new double[100];
transactions[0] = balance;
transactionsSummary = new String[100];
transactionsSummary[0] = "A balance of : " + balance
+ " was deposited. ";
numOfTransactions = 1;
}
public int getAccountNum() {
return accountNum;
}
public int getNumberOfTransactions() {
return numOfTransactions;
}
public void deposit(double amount) {
if (amount <= 0) {
System.out.println("Amount to be depsited should be positive");
} else {
balance = balance + amount;
transactions[numOfTransactions] = amount;
transactionsSummary[numOfTransactions] = "$"
+ Double.toString(amount) + "was deposited.";
numOfTransactions++;
}
}
public void withdraw(double amount) {
if (amount <= 0) {
System.out.println("Amount to be withdrawn should be positive");
} else {
balance = balance - amount;
transactions[numOfTransactions] = amount;
transactionsSummary[numOfTransactions] = "$"
+ Double.toString(amount) + "was withdrawn.";
numOfTransactions++;
}
}
}
SavingAccount.java
package bankapp;
public class SavingAccount extends BankAccount {
// create a interest field with default value 1%
private double interest = 1;
SavingAccount(String name, double balance) {
super(name, balance);
this.accountType = "saving";
}
public void deposit(double amount) {
if (amount <= 0) {
System.out.println("Amount to be depsited should be positive");
} else {
//new balance includes interest
balance = balance + amount + (amount * interest) / 100;
transactions[numOfTransactions] = amount;
transactionsSummary[numOfTransactions] = "$"
+ Double.toString(amount) + "was deposited.";
numOfTransactions++;
}
}
}
CheckingAccount.java
package bankapp;
public class CheckingAccount extends BankAccount {
CheckingAccount(String name, double balance) {
super(name, balance);
this.accountType = "checking";
}
}
Explanation / Answer
CheckingAccount.java
package bankapp;
public class CheckingAccount extends BankAccount {
CheckingAccount(String name,double balance) {
super(name,balance);
this.accountType=”checking”; }
float Interest,displayBalance;
float Interest() {
if(balance<1000) {
balance=balance*0.01f;
} else if(balance<10000)
{
balance=balance*0.02f;
} else if (balance>10000)
{
balance=balance*0.03f; }
return balance;
}
float displayBalance(){
return balance; }
}
ExtendedSavingAccount.java
package bankapp;
public class ExtendedSavingAccount extends BankAccount {
ExtendedSavingAccount(String name,double balance) {
super(name,balance);
this.accountType=”saving”; }
float interestRate,displayBalance,balance;
int lts;
float interestRate()
{
if(lts<30)
{
balance=balance*0.05f;
} else if(lts<60)
{
balance=balance*0.06f;
} else if (lts<90)
{
balance=balance*0.08f;
}else if(lts<180) {
balance= balance*0.1f;
}
return balance;
}
float displayBalance(){
return balance; }
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.