Question

In: Computer Science

Write a program to create a bank account and to process transactions. Call this class bankAccount...

Write a program to create a bank account and to process transactions. Call this class bankAccount

  • A bank account can only be given an initial balance when it is instantiated. By default, a new bank account should have a balance of 0.
  • A bank account should have a public get method, but no public set method.
  • A bank account should have a process method with a double parameter to perform deposits and withdrawals. A negative parameter represents a withdrawal. It should not be possible to withdraw more than the current balance.
  • A bank account should print method so that it can be printed easily. It should print as "The current balance is $___", with the correct value in the blank.
  • write toString() method
  • Write a driver program name it runAccount to input an amount from the user and instantiate a bank account with that initial balance, then input transactions until the user chooses to quit, printing the bank account after each transaction.
  • Write a default constructor that initializes account balance zero

Solutions

Expert Solution

Driver program

​

import java.util.ArrayList;
import java.util.Scanner;

public class runAccount {

        public static void main(String[] args) {
                

                String str = "";
                int choice;
                double balance;
                double initialAmount;
                int wish;
                int index = -1;
                double depositAmount;
                double withdrawAmount;
                ArrayList<bankAccount> b = new ArrayList<>();
                
                Scanner sc = new Scanner(System.in);
                System.out.println("welcome!");
                while(str != "q")
                {
                        System.out.println("Choose the option below!");
                        System.out.println("1.Create a new Account!");
                        System.out.println("2.Deposit money");
                        System.out.println("3.Withdraw money");
                        System.out.println("4.Show balance");
                        
                        do{
                                System.out.println("Enter your choice between 1 and 4");
                            choice = sc.nextInt();
                        }while(choice < 1 || choice > 4);
                        
                        if(choice == 1)
                        {
                                System.out.println("Creating a new Account...");
                                System.out.println("want to give an initial amount? 1 = yes ; 0 = no ");
                                wish = sc.nextInt();
                                if(wish == 1)
                                {
                                        System.out.println("Enter your amount.");
                                        initialAmount = sc.nextDouble();
                                        index++;
                                    b.add(new bankAccount(initialAmount));
                                    
                                }else
                                {
                                        b.add(new bankAccount());
                                }
                        }
                        System.out.println("Your Account has been created!");
                        b.get(index).printBal();
                        
                        if(choice == 2)
                        {
                                System.out.println("Enter the money to deposit");
                                depositAmount = sc.nextDouble();
                                b.get(index).withdraw(depositAmount);
                                b.get(index).printBal();
                        }
                        
                        if(choice == 3)
                        {
                                System.out.println("Enter the money to withdraw");
                                withdrawAmount = sc.nextDouble();
                            b.get(index).withdraw(withdrawAmount);
                            b.get(index).printBal();
                        }
                        
                        if(choice == 4)
                        {
                                b.get(index).printBal();
                        }
                        System.out.println("press 'q' to quit");
                        str = sc.next();
                }
        }

}

​

bankAccount class:


public class bankAccount {

        private double balance;
        public bankAccount()
        {
                balance = 0;
        }
        
        public bankAccount(double bal)
        {
                balance = bal;
        }
        
        private void setBal(double bal)
        {
                balance = bal;
        }
        
        public double getBal()
        {
                return balance;
        }
        
        public void deposit(double bal)
        {
                balance = balance + bal;
        }
        
        public void withdraw(double bal)
        {
                balance = balance - bal;
        }
        
        public void printBal()
        {
                System.out.println("The current balance is $" + balance);
        }
}

Related Solutions

(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main()...
(In C++) Bank Account Program Create an Account Class Create a Menu Class Create a main() function to coordinate the execution of the program. We will need methods: Method for Depositing values into the account. What type of method will it be? Method for Withdrawing values from the account. What type of method will it be? Method to output the balance of the account. What type of method will it be? Method that will output all deposits made to the...
Write a Java program to process the information for a bank customer.  Create a class to manage...
Write a Java program to process the information for a bank customer.  Create a class to manage an account, include the necessary data members and methods as necessary.  Develop a tester class to create an object and test all methods and print the info for 1 customer.  Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor.  Bonus is 2% per year of deposit, if the amount is on deposit for 5 years...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Write a C++ program (The Account Class) Design a class named Account that contains (keep the...
Write a C++ program (The Account Class) Design a class named Account that contains (keep the data fields private): a) An int data field named id for the account. b) A double data field named balance for the account. c) A double data field named annualInterestRate that stores the current interest rate. d) A no-arg constructor that creates a default account with id 0, balance 0, and annualInterestRate 0. e) The accessor and mutator functions for id, balance, and annualInterestRate....
With PHP Create a class called Account that a bank might use to represent customers' bank...
With PHP Create a class called Account that a bank might use to represent customers' bank accounts. Your class should include one data member of type int to represent the account balance. Your class should provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, the balance should be set to 0 and the...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and...
JAVA PROGRAM: Creates a Bank Account class with one checking account and methods to withdraw and deposit. Test the methods in the main function.
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT