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...
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number...
13. The class bankAccount stores a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. This class provides the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. b. The class  checkingAccount from the class bankAccount (designed in part a). This class inherits members to store the account number and the balance from the base class. A customer...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that...
a. Define the class bankAccount to store a bank customer’s account number and balance. Suppose that account number is of type int, and balance is of type double. Your class should, at least, provide the following operations: set the account number, retrieve the account number, retrieve the balance, deposit and withdraw money, and print account information. Add appropriate constructors. b. Every bank offers a checking account. Derive the class checkingAccount from the class bankAccount (designed in part (a)). This class...
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)...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount...
java Objective: Create a class. Create objects. Use methods of a class. Create a class BankAccount to represent a bank account according to the following requirements: A bank account has three attributes: accountnumber, balance and customer name. Add a constructor without parameters. In the initialization of the attributes, set the number and the balance to zero and the customer name to an empty string. Add a constructor with three parameters to initialize all the attributes by specific values. Add a...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account...
1.   Design a class called BankAccount. The member fields of the class are: Account Name, Account Number and Account Balance. There are also other variables called MIN_BALANCE=9.99, REWARDS_AMOUNT=1000.00, REWARDS_RATE=0.04. They look like constants, but for now, they are variables of type double Here is the UML for the class:                                                         BankAccount -string accountName // First and Last name of Account holder -int accountNumber // integer -double accountBalance // current balance amount + BankAccount()                     //default constructor that sets name to “”,...
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();...
Write a Java program for a simple bank account. You shall define a Customer class: A...
Write a Java program for a simple bank account. You shall define a Customer class: A customer has a first name, last name, and social security number. The social security number is a String variable and must comply with this format: xxx-xx-xxxx where 'x' is a digit between 0-9. If a customer is supplied with an invalid SSN, a message must be printed stating SSN of the customer is invalid; however, the account still is created. You shall define a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT