Assignment 2: Financial Aid Calculation (25 Points)
Chris Tralie (with heavy inspiration from Ann Marie Veca-Schilling)
Due Monday 2/10/2020
Overview / Logistics
The purpose of this assignment is to get you practice with if statements
and if/else
statements, as well as unit tests with JUnit. It will also serve as a gentle introduction/sneak preview of methods. The concept for the programming part of this assignment was borrowed heavily from Professor Schilling's version of CS 173.
Click here to download the skeleton code for this assignment. You will be editing src/hw2/HW2.java
and test/hw2/HW2Test.java
.
What to submit: When you are finished, you should submit these two files to Canvas. Please also submit answers to the following as a comment on Canvas:
- Did you work with a buddy on this assignment? If so, who?
- Are you using up any grace points to buy lateness days? If so, how many?
- Approximately how many hours it took you to finish this assignment (I will not judge you for this at all...I am simply using it to gauge if the assignments are too easy or hard)
- Your overall impression of the assignment. Did you love it, hate it, or were you neutral? One word answers are fine, but if you have any suggestions for the future let me know.
- Any other concerns that you have. For instance, if you have a bug that you were unable to solve but you made progress, write that here. The more you articulate the problem the more partial credit you will receive (fine to leave this blank)
The Problem
A non-governmental organization got a large donation to help families in need, but they have so many families to help that they need a program to help automate calculating the amount of financial assistance for each family. The amount of aid depends both on the annual household income and the number of children in the family. The rules are as follows:
-
If the annual household income is greater than $40,000, then no aid is provided.
-
If the annual household income is between $30,000 (inclusive) and $40,000 (inclusive), then apply the following rules:
- If the household has three or more children, provide $1,000 per child.
- If the household has two or fewer children, provide $500 per child.
-
If the annual household income is from $20,000 (inclusive) to $30,000 (not inclusive), then apply the following rules:
- If the household has at least two children, then provide $1,500 per child.
- If the household has only one child, then provide $2,000 total.
- If the annual household income is less than $20,000, then provide $2100 per child.
Programming Tasks (15 Points)
You have two main tasks to do to complete a working program:
- (2 points) Complete an input prompt asking the user to input an integer representing the number of kids who need assistance (this is by far the quicker part).
- (13 points) Fill in the method that computes the proper amount of assistance, following the rules above.
- Extra Credit (+2): Print the money with commas in appropriate spots. For example, print $12,000 instead of $12000. You can assume that the amount of aid is less than a million dollars, so that you will need at most one comma.
Tips
- It is possible to do this assignment with a single stream of if/else blocks that use boolean expressions, but you may instead want to do it with nested if statements in some of them (it's your choice). Recall that a nested if statement is a statement such as
c > d
unlessa > b
passes. Just for contrast, the way to get to inner block 1 without nested if statements is with a boolean expression
Unit Tests (10 Points)
Coming up with proper test cases is an important part of software engineering that, when done properly, saves everyone a huge headache. Good software testing frameworks allow the programmer to write a whole battery of tests that get applied every time the code is changed so that they don't have to manually input all of the tests every time. In NetBeans, we have access to one such test framework known as JUnit, which runs a battery of tests completely separately from the main function (more information about JUnit in Netbeans can be found here). To create your tests, you will be editing the file HW2Test.java
in the TestPackages
pane of your NetBeans project. To run the unit tests, right click on this file and select "run," as shown below
The results of all of the tests will be shown in the console. For instance, for the default skeleton code, I provided two tests, and one of them fails:
The reason for this behavior is as follows. By default, the code returns a "dummy value" of $0.0 for all income levels and number of children. The first test has a high income that should receive zero aid, so this passes just fine. However, the second case has a mid level income of $35,000 with 5 kids, that should receive a total of $5,000 in aid by the rules above. In this case, the dummy value of $0.0 is definitely not correct, so this second test will fail until you update your code.
To get full credit for this part of the assignment, you must create enough unit tests so that every block of code you write is covered by at least one test. The reference solution has 6 test cases, including the first two that are provided. The easiest way to create a new test case is to simply copy and paste the code for a test case that's already there (starting with @Test
and continuing through the end curly brace } ) and to rename it and update the test values. It is recommended that you do this as you are going along. This will really help you when debugging, and it's a lot easier than inputting values into the console over and over again.