-
Notifications
You must be signed in to change notification settings - Fork 17
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
96f2bb2
03b7f95
ba1263e
f708ce9
fd8daad
43e5a39
41d88af
5a2f513
5d505a4
890a11c
959cd86
5bc91c3
63637e8
aadf007
1f2c7f2
2d63317
93aeb71
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>(); | ||
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))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I usually recommend having the |
||
String result = PrintPovertyInfo.getMinimumChildPovertyRecord(); | ||
String result = PrintPovertyInfo.getMinimumChildPovertyRecord("Washington"); | ||
System.out.println(result); | ||
String result2 = PrintPovertyInfo.getMinimumChildPovertyRecord("South Dakota"); | ||
System.out.println(result2); | ||
|
||
} | ||
|
||
} |
There was a problem hiding this comment.
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 theDictionary
instead