The public methods of the bankaccount class

Assignment Help Basic Computer Science
Reference no: EM13969549

The objectives of this assignment are to:

  • Be able to write a Java class definition with amainmethod that creates and uses instances (Objects) of another class.
  • Be able to declare Java variables that refer to a class data type, in this project theBankAccountclass, and are initialized by instances of that class (by calls to the class constructor).
  • Be able to use the public methods, such asgetandsetmethods of an Object to read and write values stored in that Object.
  • Understand that the data stored in an Object can only be accessed by the public methods defined in that Object's class definition.

This assignment is based on your use of the public methods of the BankAccount class, provided below, to modify the checking and savings accounts of two individuals: Nick and Carol. Your job is to create a BankingDriver class and write statements in its main method that carry out the actions specified in the Project Requirements list below. Your statements must use the public methods provided by the BankAccount class. You will submit the BankingDriver.java code as your solution to this problem.

The BankAccount class definition:

/* This class encapsulates data for checking and savings acounts 
and provides an API that allows deposits and withdrawals to be made
to these accounts.
*/
public class BankAccount{
      private String name;
      private int checkMoney;
      private int saveMoney;

       public BankAccount(String who, int checking, int saving){
         name = who;
         checkMoney = checking;
         saveMoney = saving;
      }

       public String getAccountName(){
         return name;
       }

       public int getCheckMoney(){
         return checkMoney;
       }

       public int getSaveMoney(){
         return saveMoney;
       }

       public void makeCheckingDeposit(int amt){
           checkMoney = checkMoney + amt;
       }

       public void makeSavingsDeposit(int amt){
         saveMoney = saveMoney + amt;
       }
       
       public void makeCheckingWithdrawal(int amt){
        if(checkMoney >= amt)
         checkMoney = checkMoney - amt;
       }
       
       public void makeSavingsWithdrawal(int amt){
        if(saveMoney >= amt)
         saveMoney = saveMoney - amt;
       }
       
       //prints name and both account balances to the console
       public void printReport() {
         System.out.println(name + " checking: " + checkMoney + " savings: " + saveMoney);
       }
   }

Project Requirements

This is what your code must do:

  1. Create aBankAccountobject callednicksAcctsuch that Nick initially has $450 in his checking account, and $550 in his savings account.
  2. Create aBankAccountobject calledcarolsAcctsuch that Carol initially has $600 in her checking account, and $700 in her savings account.
  3. Print out a report of the checking and savings information on both Nick's and Carol's accounts using theprintReportmethod in theBankAccountclass. The output should look like this:Nick checking: 450 savings: 550
    Carol checking: 600 savings: 700
  4. Print out the sum of all money in both Nick's and Carol's savings and checking accounts. That is, the sum of Nick's savings and checking added to the sum of Carol's savings and checking. (you must use methods from theBankAccountclass here to obtain the the various amounts that contribute to the final total). The output should look like this:
    Total money in all accounts: $2300
  5. Deposit $100 to Nick's checking account using the appropriateBankAccountclass method.
  6. Print out a report of the checking and savings information onNick's account onlyusing the appropriate method in theBankAccountclass (same method used in step 3).
  7. In a series of statements, move all of the money in Nick's accounts - both checking and savings - to Carol's checking account. This should leave Nick with no money at the end- i.e. both of his accounts have 0 money. There are several ways this may be accomplished. A suggestion is to use one or more intermediate variables to hold the values from Nick's account, then deposit that value to Carol's checking account. Note: you must get the values from Nick's account by calling the methods defined in theBankAccountclass.
  8. Print out a report of the checking and savings information on both Nick's and Carol's accounts using the appropriate method in theBankAccountclass. (same as step 3).

The correct output on the examples above would be: 
Nick checking: 450 savings: 550
Carol checking: 600 savings: 700
Total money in all accounts: $2300
Nick checking: 550 savings: 550
Nick checking: 0 savings: 0
Carol checking: 1700 savings: 700

Remember- You must use the public methods of the BankAccount class in your code to achieve the steps listed above to get full credit. Pretend theBankingDriver does not know the amounts in the two BankAccount objects and has to use their public methods to get these values.

Reference no: EM13969549

Questions Cloud

Number of letters in front of terry : On Thursday, Daisy, Lookout Ltd's secretary, puts a number of letters in front of Terry for his sig- nature. Terry is busy talking to the workshop manager at the time and signs his name without reading each one. He has now discovered that one of t..
Explain lzss compression and what are the improvements of : Explain LZSS compression and what are the improvements of LZSS on LZ77
Methods of user-based and user-controlled navigation : Discuss different methods of user-based and user-controlled navigation. Define five common types of links used in a navigation system.
Prepare a case study on turkell stud mill case : Prepare a case study on "Turkell Stud Mill Case". Analysis Coherent flow; adequate research; presentation of the key issues and concerns related to the situation.
The public methods of the bankaccount class : The public methods of the BankAccount class in your code to achieve the steps listed above to get full credit. Pretend theBankingDriver does not know the amounts in the two BankAccount objects and has to use their public methods to get these values.
Write the maxterm expansion for f : A combinational switching circuit has four inputs and one output as shown. F = 0 iff three or four of the inputs are 1.    a.  Write the maxterm expansion for F.
Customers on the afternoon of the party : She sets up a home catering business and immediately agrees to cater for 100 people attending a 21st birthday party for a price of £300. She insists on £100 deposit. As the day for the party approaches, she finds that she has taken on too much wor..
Semiannual interest payments : Company B issued $3,000,000 of a bond on 1-1-x1. Since the market interest rates were lower than the bond interest rate, the bonds were sold for a premium. The company received $3,200,000 for the bonds with a 20 year life, 10%, semiannual interest pa..
Affect varied locations to different extents : In this course we examine a number of environmental impacts, and some of them may be of particular concern in your local area. Environmental impacts like urban sprawl, air and water pollution, and rapid urban growth (just to name a few) tend to affec..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Why would a manufacturer choose such a peculiar number

A certain computer can be equipped with 1,073,741,824 bytes of memory. why would a manufacturer choose such a peculiar number, instead of an easy-to-remember number like 1,000,000,000?

  What is the second system effect

Define the three phases of a project according to Brooks and what "working in parallel" means as it effects a project.

  Application patch management

Application Patch Management Select three applications (not operating systems) that you frequently use. How does each of them address patch management? Visit their Web sites to determine facilities they have to alert users to new vulnerabilities.

  The consistency between all elements of the design

The consistency between all elements of the design

  Disaster recovery or business continuity

The following summary must be at least 300 words and list the URL for the article you summarize. Find an online article regarding Disaster Recovery OR Business Continuity.

  Design interface for government for identifying terrorists

As part of the design team on a major government defense project, it is time to create your first mock-up of this terrorist identification and tracking user interface.

  Efficiency and effectiveness metrics

Choose any of the Perspective boxes in this chapter or the opening case. Then, identify and describe at least seven metrics that could be used to measure the success of the IT systems in your chosen example. For each metric, categorize it as eit..

  Computing conditional probability

Pprocessor failed sometime in the interval [4; 8] years. Given this information, what is the conditional probability that it failed before it was 5 years old?

  What opportunities enabled team to accomplish its goals

What motivational theories do you think could have been used to encourage the team to be more successful? What specific rewards or opportunities would have enabled the team to accomplish its goals? Why?

  Family reliant on wood products from the forest

You have moved to a small village in a developing country. The people in this village rely on the nearby forest for the wood they use for cooking. The forest officially is a park and should not be harvested, but there are very few park rangers, and m..

  How might bpr be used in your organization

Discuss why a company would purchase a system rather than build it themselves.

  In which case there are no pricing changes

Finally, your management-side software should write to a file the status of the reservations; that is, which house is rented to whom, when, and for what price.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd