CSC171 Introduction to Computer Programming
Fall 2018
Homework 4

  1. Modify the Account class to provide a service that allows funds to be transferred from one account to another. Note that a transfer can be thought of as withdrawing money from one account and depositing to another (for full credit, have your transfer method invoke the withdraw and deposit methods appropriately). Modify the main method of the Transactions class to demonstrate this new service.

    Here's a prototype / header for the new transfer method of the Account class:
    public void transfer (Account acctToWithdrawFrom, double amountToTransfer, double fee)
    // Note: The fee is charged to the account from which the amount is withdrawn.

  2. Modify the Transactions class above so that the data for the accounts are read from an input file; each line of the input file should correspond to the data for a single account; include data for 3 accounts e.g.:
    Ted Murphy,72354,102.56
    Jane Smith,69713,40.00
    Edward Demsey,93757,759.32
    
    In the first line of this example, the account holder's name is "Ted Murphy", the account number is 72354 and the initial balance is 102.56. (You may refer to the example NameReader.java which reads from text file names.txt .) Insert the missing code in InputManager.java which has a method for you to call from your Transactions class to read one line from a text file (e.g. accounts.txt) and returns an Account with the data from that line. Call the method readOneAccountFrom each time you need to read one line of account data from the input file, e.g.:
    // In main method of Transactions
    Account acct1 = InputManager.readOneAccountFrom (inputSource); // inputSource is a Scanner object.
    

  3. The Employee class has Javadoc style comments for the constructor and each method, but the body of each method and constructor is empty. Implement each method and constructor according to the documentation provided. (Do not modify the method headers.) Write test cases in the main method of Driver class TestEmployee.java and check that for each test case, the expected result matches the actual result. Considering that 0 is a boundary value for hours worked and hourly rate (see the documentation for the method valid), update the test method so that it includes test cases that invoke methods appropriately for the following employees:
    • an employee with hours worked < 0, hourly rate < 0
    • an employee with hours worked < 0, hourly rate = 0
    • an employee with hours worked < 0, hourly rate > 0
    • an employee with hours worked = 0, hourly rate < 0
    • an employee with hours worked = 0, hourly rate = 0
    • an employee with hours worked = 0, hourly rate > 0
    • an employee with hours worked > 0, hourly rate < 0
    • an employee with hours worked > 0, hourly rate = 0
    • an employee with hours worked > 0, hourly rate > 0

Test cases count for 25% of the grade. Readability counts for 30%. Correctness counts for 45%. Follow the programming conventions/guidelines we discussed.

Hand in a printout of your programs and outputs. For part 2, also include your text file. The assignment may be done individually or in pairs (group of 2, following the principles of pair programming as discussed in class). If you work with someone else, hand in ONE copy with both names on it.

[Back to the Assignments Index]