Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poverty project #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions PovertyInfo/src/stateinfo/PrintPovertyInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,40 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.io.IOException;

public class PrintPovertyInfo {

public static String getMinimumChildPovertyRecord() throws IOException {
BufferedReader abc = new BufferedReader(new FileReader("support/povWA.txt"));
private static final Map<String, String> stateFiles;
static
{
stateFiles = new HashMap<String, String>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap works here, might recommend using the Dictionary instead

stateFiles.put("Washington", "support/povWA.txt");
stateFiles.put("South Dakota", "support/povSD.txt");
}

public static String getMinimumChildPovertyRecord(String state) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(stateFiles.get(state)));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if one is particularly better than the other for this specific case, but I would look into the difference between the BufferedReader and the Scanner. As a start

List<String> list = new ArrayList<String>();
String str;

while((str = abc.readLine()) != null){
while((str = br.readLine()) != null){
list.add(str);
}

abc.close();
br.close();
return list.get(0);
}

public static void main(String[] args) throws IOException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually recommend having the main method in a separate file from the rest of the code, so consider separating this out

String result = PrintPovertyInfo.getMinimumChildPovertyRecord();
String result = PrintPovertyInfo.getMinimumChildPovertyRecord("Washington");
System.out.println(result);
String result2 = PrintPovertyInfo.getMinimumChildPovertyRecord("South Dakota");
System.out.println(result2);

}

}