Question

In: Computer Science

There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add...

There are two kinds of bank accounts: checking and savings. You can deposit to (i.e. add money in) or withdraw (i.e. take money out) from an account. A checking account can be withdrawn with an unlimited number of times. A savings account can only be withdrawn at most N times per calendar month. Checking accounts have no monthly fee. Savings accounts have a fixed monthly fee X. But if you deposit at least a money amount of M each month, that fee is waived. You cannot overdraft (take out more money than the current balance) a savings account. For a checking account, if you overdraft, you will have to pay an overdraft fee. 1. Design 3 classes: Account, CheckingAccount, and SavingsAccount 2. Determine the fields and methods of each class. 3. Implement the methods to deposit and withdraw. Please use java for the code.

Solutions

Expert Solution

// file name Account.java

//Run the code once you will understand the flow
import java.io.*;
import java.util.Scanner;
public class Account{
//Assuming that fee is 50 and it will be waived of when he do two deposits in a month
static int amount=1000,fee=50,money=2000,free=5;
// amount is used as base amount, money is the amount which is tha base amount for waivering of the transaction fee
static int c=0;
// c is used to continue the loop
   public static void main (String[] args) {
   int a,b;
   while(c==0){
   System.out.println("please select type of 1 CheckingAcount 2 SavingsAccount 3 exit");
// select the type of account
   Scanner scanner=new Scanner(System.in);
   a=scanner.nextInt();
   if(a==1){
   CheckingAccount check=new CheckingAccount();
   System.out.println("Please select action 1.Withdraw 2. deposit 3.exit");
   //selection of operation
   b=scanner.nextInt();
   if(b==2){
   check.deposit();
   }
   else if (b==1){
   check.withdraw();
   }
   else if(b==3){
   c=1;
   // to exit from the transaction
   System.out.println("Thank you");
   }
   else{
   //if wrong choice
   System.out.println("enter correct Choice");
   }
   }
   else if(a==2){
   SavingsAccount saving=new SavingsAccount();
   System.out.println("Please select action 1.Withdraw 2. deposit 3.exit");
   b=scanner.nextInt();
   if(b==2){
   saving.deposit();
   }
   else if (b==1){
   saving.withdraw();
   }
   else if(b==3){
   c=1;
   //to exit from transaction updating c value
   System.out.println("Thank you");
   }
   else{
   System.out.println("enter correct Choice");
   }
  
   }
   else if(a==3){
   c=1;
   System.out.println("Thank you");
   }else{
   System.out.println("Please select Correct Option");
   }
   }
   }
}
class CheckingAccount extends Account{
void deposit(){
int amt;
System.out.println("Enter Amount to deposit and press enter");
Scanner scanner=new Scanner(System.in);
amt=scanner.nextInt();
super.amount+=amt;
System.out.println("Amount deposited Success fully"+amt+"Balance i s"+super.amount);
System.out.println("Press 1 to do another transaction 2 to exit");
// to do another transaction
int opt=scanner.nextInt();
if(opt==2)
super.c=1;
// to break the loop and out from transaction
  
  
}
void withdraw(){
int amt;
System.out.println("Enter Amount to withdraw");
Scanner scanner=new Scanner(System.in);
amt=scanner.nextInt();
if(amt<super.amount){
super.amount-=amt;
System.out.println("Collect the cash Thank you");
System.out.println("Available balance is"+super.amount);
}
else{
System.out.println("Insufficient Balance"+super.amount+"Press 1 to overdraft 2 to exit");
int opi=scanner.nextInt();
if(opi==1){
super.amount-=amt;
System.out.println("overdraft is"+super.amount);
//overdraft
}
  
}
System.out.println("Press 1 to do another transaction 2 to exit");
int opt=scanner.nextInt();
if(opt==2)
super.c=1;
//to do another transaction
  
}
  
  
}
class SavingsAccount extends Account{
void deposit(){
int amt;
System.out.println("Enter Amount to deposit and press enter");
Scanner scanner=new Scanner(System.in);
amt=scanner.nextInt();
super.amount+=amt;
//waivering of transaction fee if deposited amount is greater than the selected amount
if(amt>super.money)
super.fee=0;
System.out.println("Amount deposited Success fully"+amt+"Balance i s"+super.amount);
System.out.println("Press 1 to do another transaction 2 to exit");
int opt=scanner.nextInt();
if(opt==2)
super.c=1;
  
  
}
void withdraw(){
int amt;
System.out.println("Enter Amount to withdraw");
Scanner scanner=new Scanner(System.in);
amt=scanner.nextInt();
  
if(amt<super.amount){
if(super.free==0 && super.fee==50){
System.out.println("You will be charged an extra transaction fee pres 1 to continue 2 to exit");
int cont=scanner.nextInt();
if(cont==1){
super.amount-=super.fee;
//reducing the count of free transactions
}
else{
//breaking the transaction and returing to the main
return ;
}
}
super.amount-=amt;
System.out.println("Collect the cash Thank you");
super.free-=1;
System.out.println("Available balance is"+super.amount);
}
else{
System.out.println("Insufficient Balance"+super.amount);
}
System.out.println("Press 1 to do another transaction 2 to exit");
int opt=scanner.nextInt();
if(opt==2)
super.c=1;
  
}
  
}


Related Solutions

Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts. in if and else statments only in c++
assigsment-Write a program to simulate a bank transaction. There are two bank accounts: checking and savings....
assigsment-Write a program to simulate a bank transaction. There are two bank accounts: checking and savings. First, ask for the initial balances of the bank accounts; reject negative balances. Then ask for the transactions; options are deposit, withdrawal, and transfer. Then ask for the account; options are checking and savings. Then ask for the amount; reject transactions that overdraw an account. At the end, print the balances of both accounts. in c++ work done- output and need help with the...
Spartan Credit Bank is offering 5.8 percent compounded daily on its savings accounts. You deposit $4,200...
Spartan Credit Bank is offering 5.8 percent compounded daily on its savings accounts. You deposit $4,200 today a. How much will you have in the account in 6 years? (Use 365 days a year. Do not round intermediate calculations and round your answer to 2 decimal places, e.g., 32.16.) b. How much will you have in the account in 11 years? (Use 365 days a year. Do not round intermediate calculations and round your answer to 2 decimal places, e.g.,...
Imagine that you deposit $25,000 in currency into your checking account at the bank. Assume that...
Imagine that you deposit $25,000 in currency into your checking account at the bank. Assume that this bank has a required reserve ratio of 25%. As a result of this deposit, what is the maximum amount increase in deposits in all the banks in the banking system? a. $18,750 b. $25,000 c. $31,250 d. $100,000 4
You can deposit your savings at the Texas Capital Bank, which offers to pay 13.6 percent...
You can deposit your savings at the Texas Capital Bank, which offers to pay 13.6 percent annually, interest compounded quarterly, or at Midfirst Bank, which will pay interest of 13.4 percent annually, compounded daily. With this information, which bank’s offer should you choose? Texas Capital Bank because its Effective Annual Rate (EAR) is higher. Midfirst Bank because its EAR is higher. Midfirst Bank because the nominal rate (Inom) is lower Texas Capital Bank because the (Inom) is higher. Cannot compare,...
Suppose that you deposit $391 in a savings account at Prosperity Bank at the end of...
Suppose that you deposit $391 in a savings account at Prosperity Bank at the end of each of the next 10 months. You plan to leave these contributions and any interest earned in the account until 10 months are up. The interest rate is 6.38% per month. What is the future value of your account at the end of the holding period? Do not round at intermediate steps in your calculation. Round your final answer to the nearest penny. Do...
Suppose you deposit $4,000 in currency into your checking account at Bank of America. Assume that...
Suppose you deposit $4,000 in currency into your checking account at Bank of America. Assume that Bank of America has no excess reserves at the time you make your deposit and that the required reserve ratio is 10 percent. 1) Use a T-account to show the initial effect of this transaction on bank of America's balance sheet. 2) Suppose that Bank of America makes the maximum loan they can from the funds you deposited. Use a T-account to show the...
You are at your local bank intending to deposit your savings. Explain why you would not...
You are at your local bank intending to deposit your savings. Explain why you would not offer a loan, at an interest rate that is higher than the rate the bank pays on your deposits (but lower than the rate the bank charges for car loans), to the next individual who enters the bank to apply for a car loan.
Suppose you need to deposit money in a savings account. Bank X offers a rate of...
Suppose you need to deposit money in a savings account. Bank X offers a rate of 10.200% compounded monthly; Bank Y offers a rate of 10.150% compounded quarterly; Bank Z offers a rate of 10.400% compounded annually. Which bank is best for you? Group of answer choices Bank X Bank Y Not enough information to answer Bank Z
An investor has the possibility to deposit $500 in one of two potential bank accounts. Account...
An investor has the possibility to deposit $500 in one of two potential bank accounts. Account A offers an interest rate of 5% p.a. compounded semi-annually whilst Account B offers an interest rate of 4.9% p.a. compounded quarterly. Which account will yield the higherfuture value?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT