In: Computer Science
Write a class FinancialAidApplicant which describes an applicant for financial aid and will be used by a financial aid officer.
Qualification is based on annual household income and the number of people in the household. If the household income is less than $20,000, the applicant automatically qualifies regardless of how few people are in the household. If the household income is at least $20,000 but at most $60,000 and there are 4 or more people in the household, the applicant qualifies. If the household income is more than $60,000 but at most $150,000 and there are 6 or more people in the household, the applicant qualifies. For all other cases, the applicant does not qualify.
A tester program is provided to you in Codecheck, but there is no starter code for class FinancialAidApplicant.
You should declare static constants for the numbers mentioned above.
The class has a constructor that takes a String, a double, and an int as parameters
public FinancialAidApplicant(String name, double income, int numberOfPeople)
It also has four methods:
• public String getName() Gets the applicant's name.
• public void setNumberOfPeopleInHousehold(int people) Sets number of people in the household
• public void setHouseholdIncome(double income) Sets a new household income
• public boolean qualifies() Returns true if the applicant qualifies and false
Method qualifies should have one if-else if-else statement instead of multiple if statements.
Code check:
public class FinancialAidApplicantTester
{
public static void main(String[] args)
{
FinancialAidApplicant applicant =
new FinancialAidApplicant("Joe Programmer",19999, 1);
System.out.printf("The name of the applicant: %s.%n", applicant.getName());
System.out.println("Expected: The name of the applicant: Joe Programmer.");
System.out.println(applicant.qualifies());
System.out.println("Expected: true");
applicant.setHouseholdIncome(20000);
applicant.setNumberOfPeopleInHousehold(3);
System.out.println(applicant.qualifies());
System.out.println("Expected: false");
applicant.setNumberOfPeopleInHousehold(4);
System.out.println(applicant.qualifies());
System.out.println("Expected: true");
applicant.setHouseholdIncome(60000);
applicant.setNumberOfPeopleInHousehold(4);
System.out.println(applicant.qualifies());
System.out.println("Expected: true");
applicant.setNumberOfPeopleInHousehold(3);
System.out.println(applicant.qualifies());
System.out.println("Expected: false");
applicant.setHouseholdIncome(60001);
applicant.setNumberOfPeopleInHousehold(6);
System.out.println(applicant.qualifies());
System.out.println("Expected: true");
applicant.setNumberOfPeopleInHousehold(5);
System.out.println(applicant.qualifies());
System.out.println("Expected: false");
applicant.setHouseholdIncome(150000);
applicant.setNumberOfPeopleInHousehold(6);
System.out.println(applicant.qualifies());
System.out.println("Expected: true");
applicant =
new FinancialAidApplicant("Mary Rowe",150001, 10);
System.out.printf("The name of the applicant: %s.%n", applicant.getName());
System.out.println("Expected: The name of the applicant: Mary Rowe.");
System.out.println(applicant.qualifies());
System.out.println("Expected: false");
}
}
PROGRAM:
Please find below the test class as per the given requirements:
File Name: FinancialAidApplicant.java
public class FinancialAidApplicant {
//constants for income and members
private static final int QUALIFYING_INCOME = 20000;//a constant for minimum income
private static final int QUALIFYING_INCOME_II = 60000;//a constant for income 60000
private static final int MAX_INCOME = 150000;//a constant for income 150000
//local private data members of the class
private String name;
private double income;
private int numberOfPeople;
public FinancialAidApplicant(String name, double income, int numberOfPeople) {//parameterized constructor
//set private data members as per the value provided in parameter
this.name=name;
this.income=income;
this.numberOfPeople=numberOfPeople;
}
public String getName() { //Gets the applicant's name.
return name;
}
public void setNumberOfPeopleInHousehold(int people) { //Sets number of people in the household
numberOfPeople= people;
}
public void setHouseholdIncome(double income) {// Sets a new household income
this.income = income;
}
public boolean qualifies() {//Returns true if the applicant qualifies and false
if(income<QUALIFYING_INCOME) {
return true; //income is less than 20000, no need to consider people, return true
}
else if(income>=QUALIFYING_INCOME && income<=QUALIFYING_INCOME_II && numberOfPeople>=4) {
return true;//people are 4 or more and income in between 20000 to 60000(including)
}
else if(income>QUALIFYING_INCOME_II && income <=MAX_INCOME && numberOfPeople >=6){
return true;//people are 6 or more and income is more than 60000 to 150000(including)
}
else {//for all other cases
return false;
}//end else part
}//end method
}
File Name: FinancialAidApplicantTester.java
This is same as shared in question. No change in the file.
SCREENSHOT:
Below is the screenshot to understand the code indentation:


OUTPUT:

**Kindly comment if you need any
assistance. Thanks!!