The results of a survey of the households in your municipali
The results of a survey of the households in your municipality have been made available. Each record contains data for one household, including a four-digit integer identification number, the annual income for the household, and the number of members in the household.
Write a class called Household to store the data for a single household. Write a program, called Survey, to read the survey results into an ArrayList of Household, perform the analyses, and display the results. You should read the survey results from System.in using no prompts. The actual survey data should be stored in a file survey.txt [in the src directory of your project] as integers separated by spaces or end-of-line separators. To run your project, redirect the file into standard input using redirection (from a command line, $java q1.Survey < survey.txt). The analysis required follows:
Count the number of households included in the survey and print a three-column table displaying the data read in.
Calculate the average household income, and list the identification number and income of each household that exceeds the average.
Determine the percentage of households with incomes below the low income cut-off (LICO) level. This level is published by Stats Canada. Use the following table:
Household members
Low Income cutoff
1
22,229
2
27,674
3
34,022
4
41,307
5
46,850
6
52,838
7
each additional person
58,827
5,989
| Household members | Low Income cutoff |
| 1 | 22,229 |
| 2 | 27,674 |
| 3 | 34,022 |
| 4 | 41,307 |
| 5 | 46,850 |
| 6 | 52,838 |
| 7 each additional person | 58,827 5,989 |
Solution
Please find below the java programs which are bug free and are in 100% running mode:
Household.java:
public class Household { // Class Household Created
int ID; // Household ID
int income; // Household Income
int members;
public Household(int id, int inc, int mem){
this.ID = id;
this.income = inc;
this.members = mem;
}
public int getID(){
return this.ID;
}
public int getIncome(){ //To fetch the income
return this.income;
}
public int getMmebers(){
return this.members;
}
}
HouseholdDriver.java:
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class HouseholdDriver {
public static void main(String[] args) throws IOException {
String fileName;
Scanner input = new Scanner(System.in);
String[] splits;
double averageIncome;
int sumIncome = 0;
int belowPowertyCount = 0;
double belowPovertyPercent;
double povertyLineIncome;
ArrayList<Household> households = new ArrayList<Household>();
System.out.println(\"Enter the input file name: \");
fileName = input.nextLine();
// This will Open the file
FileInputStream fstream = new FileInputStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
// This will Read File Line By Line
while ((strLine = br.readLine()) != null) {
splits = strLine.split(\" \");
// This will create new household object
Household household = new Household(Integer.parseInt(splits[0]), Integer.parseInt(splits[1]),
Integer.parseInt(splits[2]));
// This will add household to the list
households.add(household);
}
// This will Close the input stream
br.close();
// To calculate the avergae income
for (int i = 0; i < households.size(); i++) {
sumIncome += households.get(i).getIncome();
}
averageIncome = (double) sumIncome / households.size();
// To display the Households with income exceeding an average income
System.out.println(\"\ Households with income exceeding an average income of \" + averageIncome);
System.out.println(\"id \\t income \\t members\");
for (int i = 0; i < households.size(); i++) {
// greater then average
if (households.get(i).getIncome() > averageIncome) {
System.out.println(households.get(i).getID() + \" \\t \" + households.get(i).getIncome() + \" \\t \"
+ households.get(i).getMmebers());
}
}
// below poverty line
for (int i = 0; i < households.size(); i++) {
povertyLineIncome = 3750 + 750 * (households.get(i).getMmebers() / 2);
if (households.get(i).getIncome() < povertyLineIncome) {
belowPowertyCount++;
}
}
// calculate percentage
belowPovertyPercent = (double)belowPowertyCount / households.size() * 100;
System.out.println(\"Percent of households below poverty level = \" + belowPovertyPercent);
}
}


