Sie sind auf Seite 1von 6

CSc 110 Assignment 3 Static Methods with: Parameter Passing & Return Values The Bank Account Due:

Before your scheduled lab during the week of October 3-7.

Learning Outcomes:
When you have completed this assignment, you should understand: That passing parameters is equivalent to assignment. How to design and test static methods according to a given specification. How to use a Scanner to implement a program that collects input from the console (aka keyboard) using prompts. How to identify repetitive portions of code and replace them with a parameterized method that improves clarity and reduces the total size of your code. Limitations of the int and double types. How to build-up a complex program from simple methods (incremental development). This assignment requires that methods be used over and over for different purposes.

Problems from the Textbook:


Complete the Chapter 2 Exercises (pages 124-127) questions 4 through 8, 12 and 16 through 19. 2. Complete the Chapter 3 Self-Check Problems (pages 177-183) questions 1 through 13 and compare your answer to those given in Appendix A. Note: These are very good exercises to be doing in preparation for the upcoming midterm exam . 1.

Programming Problem Description: This assignment requires the writing of a program that simulates the tracking of a bank account, hereafter called theAccount, given a list of the monthly transactions on the account. In the simulation, the opening balance for theAccount will be read in from the keyboard. After that, a number of monthly transactions will be read and applied as updates to theAccounts balance. Finally, interest is added to theAccount and the balanced is checked to see that it is above 0.

Getting Started: Write a skeleton (that is a small program in the main() method) that prompts for and inputs the opening balance for theAccount from the keyboard. Then the program will output an "Account Report". The report should list the opening balance, the closing balance and the difference between the two (which is currently 0). Sample output of this part of the program:
B A N K A C C O U N T S I M U L A T I O N

Input the account's opening balance ==> 500 Account Reporting: Opening 500.0 Closing 500.0 Difference 0.0

Transaction Processing: 1. (Number of transactions) Alter your main method, such that it prompts for and inputs an integer representing the number of monthly transactions that will be applied to theAccount. This number will be used to control a definite loop that calls a method (described below) that inputs the transaction information and updates theAccount. Each transaction contains two strings, one that describes the transaction type, the other describes the transaction details; and the transaction contains one real number (double), the amount of the transaction. Here are 10 sample transactions:
bank deposit 2000.00 bank withdrawal -50.00 bank transfer -500.00 vendor purchase -75.26 bank cheque 250.00

2. (Read transactions) For each transaction call a method called doTransaction()that inputs the type, details and amount of the transaction, then simply prints the transaction information to the screen. (In particular, notice that the transactions are not yet applied to the account.) The method doTransaction()must have the following method signature: public static double doTransaction(Scanner in, double balance) where in is a pointer to the Scanner object that connects to the keyboard and balance is the current balance in the account. For now, use return 0; at the end of the method to provide the necessary double return type. Sample output of this part of the program, using the sample transactions:
B A N K A C C O U N T S I M U L A T I O N

Input the account's opening balance ==> 500 Number of monthly transactions ==> 5 Input: Type > Bank Details > deposit Amount > 2000.0 Bank, deposit Input: Type > Bank Details > withdrawl Amount > -50.0 Bank, withdrawl Input: Type > Bank Details > transfer Amount > -500.0 Bank, transfer Input: Type > Vendor Details > purcase Amount > -75.26 Vendor, purcase Input: Type > Payment Details > credit Amount > -200.0 Payment, credit

500.0

-50.0

-500.0

1950.0

-200.0

3. (Apply transactions) Create a method called updateTheAccount() that has the following signature: public static double updateTheAccount(double balance, double amount) where balance is the current balance in the account and amount is the amount of the current transcation. The method should return the updated account balance, adding or subtracting the amount to/from the balance. Call this method from the doTransaction() method, immediately after the transaction information was input, use the returned value to update the balance inside the doTransaction() method and now ensure that doTransaction() returns that balance to the method that called it (main(). Adjust the main method such that it outputs the changing balance as each transaction is processed.

Sample output of this part of the program, using the sample transactions:
B A N K A C C O U N T S I M U L A T I O N

Input the account's opening balance ==> 500 Number of monthly transactions ==> 5 Opening Transaction Closing Input: Type > Bank Details > deposit Amount > 2000.0 Bank, deposit Input: Type > Bank Details > withdrawl Amount > -50.0 Bank, withdrawl Input: Type > Bank Details > transfer Amount > -500.0 Bank, transfer Input: Type > Vendor Details > purchase Amount > -75.26 Vendor, purchase Input: Type > Payment Details > credit Amount > -200.0 Payment, credit Account Reporting: opening closing 500.0 1674.74 difference 1174.74

500.0

2000.0

2500.0

2500.0

-50.0

2450.0

NOTE: There is no expectation that your program rounds numbers to the nearest cent (as was done in this example.)

2450.0

-500.0

1950.0

1950.0

-75.26

1874.74

1874.74 -200.0

1674.74

Accruing Interest:

Write and call a method called applyInterest()that has the following signature: public static double applyInterest (double balance, double rate) The method adds simple interest to the accounts balance.

Sample output of this part of the program, using the sample transactions:
B A N K A C C O U N T S I M U L A T I O N

Input the account's opening balance ==> 500 Number of monthly transactions ==> 5 Opening Transaction Closing Input: Type > Bank Details > deposit Amount > 2000.0 Bank, deposit Input: Type > Bank Details > withdrawl Amount > -50.0 Bank, withdrawl Input: Type > Bank Details > transfer Amount > -500.0 Bank, transfer Input: Type > Vendor Details > purchase Amount > -75.26 Vendor, purchase Input: Type > Payment Details > credit Amount > -200.0 Payment, credit

500.0

2000.0

2500.0

2500.0

-50.0

2450.0

2450.0

-500.0

1950.0

1950.0

-75.26

1874.74

1874.74 -200.0

1674.74

Input current interest rate ==> 0.375 Account Reporting: opening closing 500.0 1681.020275 difference 1181.020275

HAND IN: Submit the final code that you produced using the Assignments link of the course web page. (Multiple submissions are allowed, so submit each part as you get it working. That ensures that you never lose your intermediate work.) Your final submission must occur before your scheduled lab the week of October 3-7.

Grading The marker will look for:


Documentation: Documentation in the implemented code must include the author's identification and the purpose of the program. Each group of instructions must be preceded with a comment describing their common purpose. Each method must be preceded with a comment describing its purpose as well as an indication of the input to and the output from the method.

White Space and Indentation in the code and adherence to Java naming conventions
Methods: The specified methods must be called repeatedly passing different value in each call. (i.e., There should NOT be multiple variations of these methods for different runs.) Your methods should accept input parameter values and return an output value exactly as described above. Other suitable methods can be created, of course, or no other methods, if that is appropriate. Compiles and produces correct output: The code constitutes a valid Java program (i.e. compiles *and* runs without error on the ECS 250 lab machines). It must accept input and print output as described above.

More to Discover
Consider the complexity of a program that would manage all the updates to all the accounts that are held within a single bank, and also the updates to the banks various operating funds. Your program could easily be expanded to do this calculation. There are, however, more efficient methods of inputting the times, making execution less tedious. The process of creating and testing a small part of the entire program, then adding on another small part and then another is called incremental development. It allows the programmer to simplify a large problem working through only a few issues at a time: http://www.highproductivity.org/r6047.pdf or http://en.wikipedia.org/wiki/Iterative_and_incremental_development.

Das könnte Ihnen auch gefallen