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

A bank determines that there are two specific kinds of bank accounts. Savings ac

ID: 3906302 • Letter: A

Question

A bank determines that there are two specific kinds of bank accounts.

Savings accounts have a customer id, balance, and overdraft amount. A customer can withdraw an amount of money from the account, but only if they don't go over the overdraft amount. For example, if the balance is $100 and the overdraft is $200, the customer can withdraw no more than $300. The customer can also deposit an amount of money to the account.

A Checking account has a customer id and balance. A customer can withdraw an amount of money from the account, but they can't withdraw more than the current balance. The customer can also deposit an amount of money to the account.

Following is the simple structure of abstract class for the program.

You can add more data member and methods in abstract class to accomplish the requirement of program.

pubic abstract class Accounts

{

    private String customerID;

    private double balance;

   public Accounts(String customerID, double balance)

    {

        this.customerID = customerID;

        this.balance = balance;

    }

   

    public abstract void deposit(double amount);

    pubic abstract void withdraw(double amount);

    OR

    public abstract double deposit();

    public abstract double withdraw();

    OR

   public abstract double deposit(double amount);

   public abstract double withdraw(double amount);

   You can use any format of abstract method to do deposit and withdraw.

}

   

Saving and checking both are subclasses of Account class.

Write your own logic for both saving and checking classes.

Write a TestProgram to create object of saving and checking classes.

Depending on saving and checking class get value of customerID, balance, overdraft amount, value to be deposit and value to be withdrawn from user.

Print total balance after withdraw and deposit for both saving and checking account.

Use menu driven structure for select either saving or checking account as per following.

Following is the sample run of program for saving account:

1. Checking Account

2. Savings Account

Choose an account: 2

Please enter a customerID for the savings account: 101

Please enter a starting balance for the savings account: 100

Please enter the overdraft limit for the savings account: 100

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 1

Please enter an amount to deposit to your savings account: 50

Amount of $50.0 deposited to account

Current account balance after deposit is $150.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 80

Amount of $80.0 successfully withdrawn

Current account balance after withdraw is $70.0

Current overdraft balance is $100.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 100

Overdraft funds required for transaction.

Amount of $100.0 successfully withdrawn

Current account balance is $0.0

Current overdraft balance is $70.0 and your original overdraft limit was: $100.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. View Account Information

4. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 100

Insufficient funds to complete transaction

Current account balance is $0.0

Current overdraft balance is 70.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 3

Submission and Marking Scheme:

Submit java zip file through drop box.

You must also copy and paste all of your source code from all of your classes into a Word document and also submit this document file separately.

Your submissions will be graded with the following consideration:

Marks will be given for originality of the code.

Program is stored in an appropriately named file

Program has the proper header information including your name and program

Program compiles successfully and without warnings

Program is complete and produces correct results

Program uses appropriate indentation to show logical path flows

Program has proper commenting

Marks will be deducted for poor commenting and/or not following Java naming conventions.

A bank determines that there are two specific kinds of bank accounts.

Savings accounts have a customer id, balance, and overdraft amount. A customer can withdraw an amount of money from the account, but only if they don't go over the overdraft amount. For example, if the balance is $100 and the overdraft is $200, the customer can withdraw no more than $300. The customer can also deposit an amount of money to the account.

A Checking account has a customer id and balance. A customer can withdraw an amount of money from the account, but they can't withdraw more than the current balance. The customer can also deposit an amount of money to the account.

Following is the simple structure of abstract class for the program.

You can add more data member and methods in abstract class to accomplish the requirement of program.

pubic abstract class Accounts

{

    private String customerID;

    private double balance;

   public Accounts(String customerID, double balance)

    {

        this.customerID = customerID;

        this.balance = balance;

    }

   

    public abstract void deposit(double amount);

    pubic abstract void withdraw(double amount);

    OR

    public abstract double deposit();

    public abstract double withdraw();

    OR

   public abstract double deposit(double amount);

   public abstract double withdraw(double amount);

   You can use any format of abstract method to do deposit and withdraw.

}

   

Saving and checking both are subclasses of Account class.

Write your own logic for both saving and checking classes.

Write a TestProgram to create object of saving and checking classes.

Depending on saving and checking class get value of customerID, balance, overdraft amount, value to be deposit and value to be withdrawn from user.

Print total balance after withdraw and deposit for both saving and checking account.

Use menu driven structure for select either saving or checking account as per following.

Following is the sample run of program for saving account:

1. Checking Account

2. Savings Account

Choose an account: 2

Please enter a customerID for the savings account: 101

Please enter a starting balance for the savings account: 100

Please enter the overdraft limit for the savings account: 100

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 1

Please enter an amount to deposit to your savings account: 50

Amount of $50.0 deposited to account

Current account balance after deposit is $150.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 80

Amount of $80.0 successfully withdrawn

Current account balance after withdraw is $70.0

Current overdraft balance is $100.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 100

Overdraft funds required for transaction.

Amount of $100.0 successfully withdrawn

Current account balance is $0.0

Current overdraft balance is $70.0 and your original overdraft limit was: $100.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. View Account Information

4. Exit

Choose a menu option for the savings account: 2

Please enter an amount to withdraw from your savings account: 100

Insufficient funds to complete transaction

Current account balance is $0.0

Current overdraft balance is 70.0

1. Deposit Amount to Savings Account

2. Withdraw Amount from Savings Account

3. Exit

Choose a menu option for the savings account: 3

Submission and Marking Scheme:

Submit java zip file through drop box.

You must also copy and paste all of your source code from all of your classes into a Word document and also submit this document file separately.

Your submissions will be graded with the following consideration:

Marks will be given for originality of the code.

Program is stored in an appropriately named file

Program has the proper header information including your name and program

Program compiles successfully and without warnings

Program is complete and produces correct results

Program uses appropriate indentation to show logical path flows

Program has proper commenting

Marks will be deducted for poor commenting and/or not following Java naming conventions.

Explanation / Answer

package inheritance;

import java.util.Scanner;

// Abstract class Accounts definition

abstract class Accounts

{

// Instance variables to store account information

private String customerID;

private double balance;

  

// Parameterized constructor to assign parameter values to instance variables

public Accounts(String customerID, double balance)

{

this.customerID = customerID;

this.balance = balance;

}// End of parameterized constructor

// Method to set balance

void setBalance(double bal)

{

balance = bal;

}// End of method

// Method to set id

void setCustomerID(String id)

{

customerID = id;

}// End of method

// Method to return id

String getCustomerID()

{

return customerID;

}// End of method

// Method to return balance

double getBalance()

{

return balance;

}// End of method

// Abstract method declaration

public abstract void deposit(double amount);

public abstract void withdraw(double amount);

}// End of class

// Class Saving derived from Accounts

class Saving extends Accounts

{

// Instance variable to store Saving account information

double overdraftBalance;

double overdraftLimit;

// Parameterized constructor to assign parameter values to instance variables

public Saving(String cusID, double bal, double amt)

{

// Calls the base class constructor

super(cusID, bal);

overdraftBalance = amt;

overdraftLimit = amt;

}// End of parameterized constructor

// Overrides method to deposit amount

public void deposit(double amount)

{

// Calls the method to add amount to balance

setBalance(getBalance() + amount);

// Displays account information

System.out.print(" Amount of $" + amount + " deposited to account " + getCustomerID());

System.out.print(" Current account balance after deposit is $" + getBalance());

}// End of method

// Overrides method to withdraw amount

public void withdraw(double amount)

{

// Checks if the amount is greater than the current balance (calls getBalance() for current balance) + overdraftBalance  

if(amount > (getBalance() + overdraftBalance))

// Displays account information

System.out.print(" Insufficient funds to complete transaction." + " Current account balance is $" + getBalance() +

" Current overdraft balance is $" + overdraftBalance);

// Otherwise checks if the amount is equals to the current balance (calls getBalance() for current balance) + overdraftBalance

else if(amount == (getBalance() + overdraftBalance))

{

// Set both the balance to zero

setBalance(0);

overdraftBalance = 0;

// Displays account information

System.out.print(" Amount of $" + amount + " successfully withdrawn from account " + getCustomerID());

System.out.print(" Current account balance after withdraw is $" + getBalance());

System.out.print(" Current overdraft balance is $" + overdraftBalance);

}// End of else if condition

// Otherwise checks if the amount is less than the current balance (calls getBalance() for current balance)

else if(amount < getBalance())

{

// Calls the method to set the balance to current balance minus amount

setBalance(getBalance() - amount);

// Displays account information

System.out.print(" Amount of $" + amount + " successfully withdrawn from account " + getCustomerID());

System.out.print(" Current account balance after withdraw is $" + getBalance());

System.out.print(" Current overdraft balance is $" + overdraftBalance);

}// End of else if condition

// Otherwise checks if the amount is greater than the current balance (calls getBalance() for current balance)

else if(amount > getBalance())

{

// Displays account information

System.out.print(" Overdraft funds required for transaction.");

System.out.print(" Amount of $" + amount + " successfully withdrawn from account " + getCustomerID());

// Subtracts current balance from the amount and then subtracts the result from overdraftBalance

overdraftBalance -= (amount - getBalance());

// Set the current balance to zero

setBalance(0);

// Displays account information

System.out.print(" Current account balance is $" + getBalance());

System.out.print(" Current overdraft balance is $" + overdraftBalance + " and your original overdraft limit was: $" + overdraftLimit);

}// End of else if condition

}// End of method

}// End of Saving class

// Class Checking derived from Accounts

class Checking extends Accounts

{

// Parameterized constructor

public Checking(String cusID, double bal)

{

// Calls the base class constructor

super(cusID, bal);

}// End of parameterized constructor

// Overrides method to deposit amount

public void deposit(double amount)

{

// Calls the method to set the balance to sum of current balance with amount  

setBalance(getBalance() + amount);

// Displays account information

System.out.print(" Amount of $" + amount + " deposited to account " + getCustomerID());

System.out.print(" Current account balance after deposit is $" + getBalance());

}// End of method

// Overrides method to withdraw amount

public void withdraw(double amount)

{

// Checks if amount is greater than the current balance (calls getBalance() for current balance)

if(amount > getBalance())

// Displays account information

System.out.print(" Insufficient funds to complete transaction." + " Current account balance is $" + getBalance());

// Otherwise

else

{

// Calls the method to set balance after subtracting amount from current balance

setBalance(getBalance() - amount);

// Displays account information

System.out.print(" Amount of $" + amount + " successfully withdrawn from account " + getCustomerID());

System.out.print(" Current account balance is $" + getBalance());

}// End of else

}// End of method

}// End of class Current

// Driver class

public class AccountsTest

{

// Scanner class object declared

static Scanner sc;

// Method to return account type enter by the user

static int AccountMenu()

{

// Scanner class object created

sc = new Scanner(System.in);

int ch;

// Displays menu

System.out.print(" 1. Checking Account, 2. Savings Account. 3 Exit.");

// Accepts user choice

System.out.print(" Choose an account: ");

ch = sc.nextInt();

// Returns choice

return ch;

}// End of method

// Method to return transaction type

// Receives account type as parameter

static int TransactionMenu(String acc)

{

// Scanner class object created

sc = new Scanner(System.in);

int ch;

// Displays menu

System.out.print(" 1. Deposit Amount to " + acc + " 2. Withdraw Amount from " + acc + " 3 Exit.");

// Accepts user choice

System.out.print(" Choose a menu option for the " + acc + ": ");

ch = sc.nextInt();

// Returns choice

return ch;

}// End of method

// main method definition

public static void main(String ss[])

{

// Scanner class object created

sc = new Scanner(System.in);

String accId;

double bal, overBal, amt;

Checking ch;

Saving sa;

// Loops till user choice is not 3

do

{

// Calls the method to accept accounts type

switch(AccountMenu())

{

// Checking Account

case 1:

// Accepts account information

System.out.print(" Please enter a customerID for the Checking Account: ");

accId = sc.next();

System.out.print(" Please enter a starting balance for the Checking Account: ");

bal = sc.nextDouble();

// Using parameterized constructor creates a Checking Account

ch = new Checking(accId, bal);

// Loops till transaction type is not 3

do

{

// Calls the method to accept transaction type

switch(TransactionMenu("Checking Account"))

{

case 1:

System.out.print(" Please enter an amount to deposit to your Checking Account: ");

amt = sc.nextDouble();

ch.deposit(amt);

break;

case 2:

System.out.print(" Please enter an amount to withdraw from your Checking Account: ");

amt = sc.nextDouble();

ch.withdraw(amt);

break;

case 3:

System.exit(0);

default:

System.out.print(" Invalid Transaction Type. Try again.");

}// End of inner switch - case

}while(true); // End of inner do - while loop

// Saving Account

case 2:

// Accepts account information

System.out.print(" Please enter a customerID for the savings account: ");

accId = sc.next();

System.out.print(" Please enter a starting balance for the savings account: ");

bal = sc.nextDouble();

System.out.print(" Please enter the overdraft limit for the savings account: ");

overBal = sc.nextDouble();

// Using parameterized constructor creates a Saving Account

sa = new Saving(accId, bal, overBal);

// Loops till transaction type is not 3

do

{

// Calls the method to accept transaction type

switch(TransactionMenu("Checking Account"))

{

case 1:

System.out.print(" Please enter an amount to deposit to your Checking Account: ");

amt = sc.nextDouble();

sa.deposit(amt);

break;

case 2:

System.out.print(" Please enter an amount to withdraw from your Checking Account: ");

amt = sc.nextDouble();

sa.withdraw(amt);

break;

case 3:

System.exit(0);

default:

System.out.print(" Invalid Transaction Type. Try again.");

}// End of inner switch - case

}while(true);// End of inner do - while loop

case 3:

System.exit(0);

default:

System.out.print(" Invalid Account Type. Try again.");

}// End of outer switch - case

}while(true); // End of outer do - while loop

}// End of main method

}// End of driver class

Sample Output:

1. Checking Account, 2. Savings Account. 3 Exit.

Choose an account: 2

Please enter a customerID for the savings account: 100

Please enter a starting balance for the savings account: 100

Please enter the overdraft limit for the savings account: 100

1. Deposit Amount to Checking Account 2. Withdraw Amount from Checking Account 3 Exit.

Choose a menu option for the Checking Account: 1

Please enter an amount to deposit to your Checking Account: 50

Amount of $50.0 deposited to account 100

Current account balance after deposit is $150.0

1. Deposit Amount to Checking Account 2. Withdraw Amount from Checking Account 3 Exit.

Choose a menu option for the Checking Account: 2

Please enter an amount to withdraw from your Checking Account: 80

Amount of $80.0 successfully withdrawn from account 100

Current account balance after withdraw is $70.0

Current overdraft balance is $100.0

1. Deposit Amount to Checking Account 2. Withdraw Amount from Checking Account 3 Exit.

Choose a menu option for the Checking Account: 2

Please enter an amount to withdraw from your Checking Account: 100

Overdraft funds required for transaction.

Amount of $100.0 successfully withdrawn from account 100

Current account balance is $0.0

Current overdraft balance is $70.0 and your original overdraft limit was: $100.0

1. Deposit Amount to Checking Account 2. Withdraw Amount from Checking Account 3 Exit.

Choose a menu option for the Checking Account: 2

Please enter an amount to withdraw from your Checking Account: 100

Insufficient funds to complete transaction.

Current account balance is $0.0

Current overdraft balance is $70.0

1. Deposit Amount to Checking Account 2. Withdraw Amount from Checking Account 3 Exit.

Choose a menu option for the Checking Account: 3

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