Question

Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task...

Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task for this assignment is to create a simple bank accounting system and demonstrate its use.

Create an Account class as per the following specifications:

  1. three private instance variables: accountOwnerName (String), accountNumber (int) and balance (double)

  2. a single constructor with three arguments: the account owner's name, accountNumber and starting balance. In the constructor, initialize the instance variables with the provided parameter values.

  3. get and set methods for each of the instance variables.

  4. A computation method, named makeDeposit, that takes the deposit amount as a decimal value for its argument. The method adds the deposit amount to the account's balance. This method doesn't return anything to the caller.

  5. A computation method, named makeWithdrawal, that takes the withdrawal amount as a decimal value for its argument. The method subtracts the withdrawal amount from the account's balance. This method doesn't return anything to the caller.

  6. A toString method to return a string containing all information stored about the account

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************Account.java*******************/

package shaky_bank;

/**
* The Class Account.
*/
public class Account {

   /** The account owner name. */
   private String accountOwnerName;

   /** The account number. */
   private int accountNumber;

   /** The balance. */
   private double balance;

   /**
   * Instantiates a new account.
   *
   * @param accountOwnerName the account owner name
   * @param accountNumber the account number
   * @param balance the balance
   */
   public Account(String accountOwnerName, int accountNumber, double balance) {
       this.accountOwnerName = accountOwnerName;
       this.accountNumber = accountNumber;
       this.balance = balance;
   }

   /**
   * Gets the account owner name.
   *
   * @return the account owner name
   */
   public String getAccountOwnerName() {
       return accountOwnerName;
   }

   /**
   * Sets the account owner name.
   *
   * @param accountOwnerName the new account owner name
   */
   public void setAccountOwnerName(String accountOwnerName) {
       this.accountOwnerName = accountOwnerName;
   }

   /**
   * Gets the account number.
   *
   * @return the account number
   */
   public int getAccountNumber() {
       return accountNumber;
   }

   /**
   * Sets the account number.
   *
   * @param accountNumber the new account number
   */
   public void setAccountNumber(int accountNumber) {
       this.accountNumber = accountNumber;
   }

   /**
   * Gets the balance.
   *
   * @return the balance
   */
   public double getBalance() {
       return balance;
   }

   /**
   * Sets the balance.
   *
   * @param balance the new balance
   */
   public void setBalance(double balance) {
       this.balance = balance;
   }

   /**
   * Make deposit.
   *
   * @param amount the amount
   */
   public void makeDeposit(double amount) {

       if (amount > 0) {

           this.balance += amount;
       } else {

           System.out.println("Balance cannot be negative!");
       }
   }

   /**
   * Make withdrawal.
   *
   * @param amount the amount
   */
   public void makeWithdrawal(double amount) {

       if (amount < balance) {

           this.balance -= amount;
       } else {

           System.out.println("Insufficient balance!!");
       }
   }

   @Override
   public String toString() {
       return "Account name: " + accountOwnerName + "\n" + "Account number: " + accountNumber + "\n" + "Balance: "
               + balance + "\n";
   }

}
/****************************Bank.java****************************/

package shaky_bank;

/**
* The Class Bank.
*/
public class Bank {

   public static void main(String[] args) {

       Account account = new Account("John Doe", 12345, 1000);

       System.out.println(account.toString());

       account.makeDeposit(200);

       System.out.println(account.toString());

       account.makeWithdrawal(500);

       System.out.println(account.toString());
   }
}
/*****************************output********************************/

Account name: John Doe
Account number: 12345
Balance: 1000.0

Account name: John Doe
Account number: 12345
Balance: 1200.0

Account name: John Doe
Account number: 12345
Balance: 700.0

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
Congratulations, you have been hired by Shaky Bank and Trust as a staff programmer. Your task...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Design and implement the following 3 classes with the exact fields and methods (these names and c...

    Design and implement the following 3 classes with the exact fields and methods (these names and caps exactly): 1. An abstract class named BankAccount (java file called BankAccount.java) Description Filed/Method Balance NumberDeposits NumberWithdrawals AnnualInterestRate MonthlyServiceCharge BankAccount SetHonthlyServiceCharges A method that accepts the monthly service charges as an argument and set the field value GetBalance GetNum berDeposits GetNum berWithdrawals GetAnnualinterestRate GetMonthlyServiceCharge A method that returns the monthly service charge Deposit field for the bank account balance A field for the number...

  • pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank...

    pls write psuedocode write UML CODE ALSO example 3 files 1 for abstract 1 for bank account and 1 for savings accounts due in 12 hours Lab Assignment 4a Due: June 13th by 9:00 pm Complete the following Programming Assignment. Use good programming style and all the concepts previously covered. Submit the java files electronically through Canvas by the above due date in 1 Zip file Lab4.Zip. (This is from the chapter on Inheritance.) 9. BankAccount and SavingsAccount Classes Design...

  • You have been hired as a programmer by a major bank. Your first project is a...

    You have been hired as a programmer by a major bank. Your first project is a small banking transaction system. Each account consists of a number and a balance. The user of the program (the teller) can create a new account, as well as perform deposits, withdrawals, and balance inquiries. The application consists of the following functions:  N- New account  W- Withdrawal  D- Deposit  B- Balance  Q- Quit  X- Delete Account Use the following...

  • You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account i...

    You are to write a banking application in c# that keeps track of bank accounts. It will consist of three classes, Account, Bank and BankTest. The Account class is used to represent a savings account in a bank. The class must have the following instance variables: a String called accountID                       a String called accountName a two-dimensional integer array called deposits (each row represents deposits made in a week). At this point it should not be given any initial value. Each...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • You are to write a Java program using the following instructions to build a bank-ATM server...

    You are to write a Java program using the following instructions to build a bank-ATM server system with sockets. A bank holds accounts that can have deposits, withdrawals, or retrievals of balance. The bank server provides the account for transactions when a client uses and ATM machine. The ATM asks for the type of transaction and the amount (if needed), then creates a socket connection to the bank to send the transaction for processing. The bank performs the transaction on...

  • Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending...

    Project 9-2: Account Balance Calculator Create an application that calculates and displays the starting and ending monthly balances for a checking account and a savings account. --->Console Welcome to the Account application Starting Balances Checking: $1,000.00 Savings:  $1,000.00 Enter the transactions for the month Withdrawal or deposit? (w/d): w Checking or savings? (c/s): c Amount?: 500 Continue? (y/n): y Withdrawal or deposit? (w/d): d Checking or savings? (c/s): s Amount?: 200 Continue? (y/n): n Monthly Payments and Fees Checking fee:              $1.00 Savings...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT