Application Objective Task 2


Time Estimate: 8 hours

Jump to current week
Requirements

Project Structure


GitHub Repository link: https://github.com/jessehartloff/AO3

  1. Clone the starter code from the repository into a new IntelliJ project

The starter code defines each method and class that will be used during testing, and you should only use these classes/methods in your tests.


First Application Objective - Constructor and Net Gains


Test and implement the constructor and netGains methods in the money.DebtCalculator class.

Testing Requirements

Test the following features of your money.DebtCalculator class:

  • A constructor that takes a filename as a String for a parameter. This will be a CSV file where each line is in the format "person1,person2,amount" meaning the person1 owes person2 the amount of dollars. All dollar values will be integers (Whole dollar amounts only). If a line is "Paul,Jesse,50" then Paul owes Jesse $50. The constructor will read this file and store all the debt information in instance variables. All CSV files should be in a directory named data
  • A method named netGains that takes the name of a person as a String and returns the net gains for that person. This is the total amount that person will have gained after all debts are settled. Net gains can be negative. For example, if Paul owes Jesse $50 and Jesse owes Leo $75, then Jesse's net gains are -$25 and the method should return -25 as an int.

Programming Requirements

Implement the tested functionality.


Second Application Objective - Detecting Cycles


Test and implement the findCycle method in the money.DebtCalculator class.

Testing Requirements

Test the following feature of your money.DebtCalculator class:

  • The findCycle method that takes no parameters and returns a reference to a Cycle object using the provided Cycle class. This method will detect if there is a cycle in the debt data and will return it if it exists. A cycle exists if there's any number of people all of whom owe money to the next person in a way the eventually returns to the original debtor. The amount of the cycle is the minimum amount owed throughout the cycle. If such a cycle exists, the amount of each debt in the cycle could be reduced by the cycle amount (You don't have to reduce the debts, just detect the cycle). For example, if Paul owes Jesse $50, Jesse owes Leo $75, and Leo owes Paul $100, there is a cycle [Paul, Jesse, Leo] of $50
  • If no cycle exists, the method returns null
  • If a cycle exists, return a Cycle object containing the names of everyone in the cycle in the order in which they appear, and the cycle amount. Note that the starting point is ambiguous so your tests must accept any valid ordering. In the example above, there are three valid orderings [Paul, Jesse, Leo], [Jesse, Leo, Paul], and [Leo, Paul, Jesse]
  • You may assume that there is at most 1 cycle in the file of data and your test cases should contain at most 1 cycle
  • A cycle can be as small as 2 nodes (eg. 2 people owe each other money)

Programming Requirements

Implement the findCycle method.