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 - Java and Python #9

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
18c1ec8
create gitignore and county and program class files
kedevlin Apr 5, 2016
69dd1c4
program captures user input
kedevlin Apr 6, 2016
ba3dfa1
update prompt
kedevlin Apr 6, 2016
464d2fe
add wa txt file, program is able to read first line from it
kedevlin Apr 6, 2016
a14c0f0
program can print a specific line
kedevlin Apr 6, 2016
9899562
program successfully finds line matching user input
kedevlin Apr 6, 2016
fcac531
add california txt file, user can choose state and county and program…
kedevlin Apr 6, 2016
91ff514
update prompt
kedevlin Apr 6, 2016
dfba932
add system output describing relevant county info
kedevlin Apr 6, 2016
ab8759e
add constructor to county class, program creates new county object if…
kedevlin Apr 6, 2016
fe894ff
add file to county class constructor
kedevlin Apr 6, 2016
7910714
remove line_num variable, change county class constructor to take in …
kedevlin Apr 6, 2016
2578d35
poverty percent is an attribute of county, program outputs this value…
kedevlin Apr 6, 2016
8d71998
program displays number of children in poverty and median household i…
kedevlin Apr 6, 2016
a7bafbf
program displays required info for user selected county
kedevlin Apr 6, 2016
bec19c8
handle other states and other input besides wa and ca
kedevlin Apr 7, 2016
1d2e7ad
change no_county variable to countyFound
kedevlin Apr 7, 2016
918960c
change user_county to userCounty
kedevlin Apr 7, 2016
3a5c908
change county attribute variable names to lower camel case
kedevlin Apr 7, 2016
74e7e31
make name name column index range constants
kedevlin Apr 7, 2016
e1a47bc
user input for state in a while loop
kedevlin Apr 7, 2016
e4ea2cb
rename scanner variables
kedevlin Apr 7, 2016
c68e21d
move close of scanInput to end of method
kedevlin Apr 7, 2016
2babb5c
move county user input to while loop
kedevlin Apr 7, 2016
269c726
remove if statement for county not found
kedevlin Apr 7, 2016
858f997
end program if q is entered for state input
kedevlin Apr 7, 2016
a497429
allow user to exit during county input loop
kedevlin Apr 7, 2016
c5fe4a7
create method to find extreme pov percents for a given state's file, …
kedevlin Apr 7, 2016
d49a95b
extreme county finder method works for finding county with lowest per…
kedevlin Apr 7, 2016
8a11323
print all required info
kedevlin Apr 7, 2016
fc72fb0
create python files
kedevlin Apr 7, 2016
564d7fb
open and close two files
kedevlin Apr 7, 2016
4f300a2
create find_extreme_county method
kedevlin Apr 7, 2016
9d54ecf
import County class in program file, return county with highest pov p…
kedevlin Apr 7, 2016
ab718b1
all required attributes for county exist and print for highest of eac…
kedevlin Apr 7, 2016
16bab6c
add if else statement for finding highest or lowest poverty in each s…
kedevlin Apr 8, 2016
3f01809
print details of highest and lowest poverty counties for each state
kedevlin Apr 8, 2016
12d00da
capture user input for state
kedevlin Apr 8, 2016
1d52abf
if else statement for setting file name or quitting program
kedevlin Apr 8, 2016
1cf4d09
capture user input for county
kedevlin Apr 8, 2016
4b6be08
create print_county method for printing matching counties and determi…
kedevlin Apr 8, 2016
323bb7f
prompt user for county until county is found or user types q
kedevlin Apr 8, 2016
6501cec
program re-prompts user for state until wa, ca, or q is entered
kedevlin Apr 8, 2016
5de7f52
remove county.pyc from git
kedevlin Apr 8, 2016
fca1bfa
update .gitignore to include pyc files
kedevlin Apr 8, 2016
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
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# Eclipse Core
.project

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# JDT-specific (Eclipse Java Development Tools)
.classpath

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/
59 changes: 59 additions & 0 deletions poverty/California.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
06 0 6253423 6203456 6303390 16.4 16.3 16.5 2040811 2011678 2069944 22.6 22.3 22.9 1424469 1398503 1450435 21.9 21.5 22.3 61927 61689 62165 575759 562058 589460 23.4 22.8 24.0 California CA est14_CA.txt 06NOV2015
06 1 197984 186953 209015 12.5 11.8 13.2 48750 43470 54030 14.3 12.8 15.8 33524 29523 37525 13.8 12.2 15.4 76996 75788 78204 Alameda County CA est14_CA.txt 06NOV2015
06 3 211 164 258 19.0 14.7 23.3 62 47 77 28.2 21.4 35.0 40 30 50 21.7 16.3 27.1 53003 48227 57779 Alpine County CA est14_CA.txt 06NOV2015
06 5 4313 3381 5245 12.9 10.1 15.7 1032 801 1263 18.6 14.4 22.8 700 537 863 16.8 12.9 20.7 54610 49602 59618 Amador County CA est14_CA.txt 06NOV2015
06 7 48151 44057 52245 21.9 20.0 23.8 10825 9111 12539 24.3 20.4 28.2 7829 6594 9064 24.2 20.4 28.0 42302 40264 44340 Butte County CA est14_CA.txt 06NOV2015
06 9 6057 4889 7225 13.7 11.1 16.3 1577 1219 1935 20.6 15.9 25.3 1091 839 1343 18.5 14.2 22.8 53321 48734 57908 Calaveras County CA est14_CA.txt 06NOV2015
06 11 3030 2458 3602 14.3 11.6 17.0 1176 930 1422 19.9 15.8 24.0 812 635 989 18.7 14.6 22.8 48006 44053 51959 Colusa County CA est14_CA.txt 06NOV2015
06 13 115466 106262 124670 10.5 9.7 11.3 35640 31659 39621 13.8 12.3 15.3 25628 22795 28461 13.3 11.8 14.8 80338 78400 82276 Contra Costa County CA est14_CA.txt 06NOV2015
06 15 5388 4271 6505 22.4 17.8 27.0 1743 1348 2138 31.0 24.0 38.0 1174 900 1448 28.9 22.2 35.6 41419 38181 44657 Del Norte County CA est14_CA.txt 06NOV2015
06 17 20715 18116 23314 11.4 10.0 12.8 4956 4049 5863 13.1 10.7 15.5 3405 2765 4045 11.5 9.3 13.7 70235 65699 74771 El Dorado County CA est14_CA.txt 06NOV2015
06 19 261387 248776 273998 27.5 26.2 28.8 104770 98420 111120 38.0 35.7 40.3 71200 66789 75611 36.3 34.0 38.6 43338 41508 45168 Fresno County CA est14_CA.txt 06NOV2015
06 21 4723 3796 5650 17.1 13.7 20.5 1751 1344 2158 23.7 18.2 29.2 1260 973 1547 23.3 18.0 28.6 43755 39548 47962 Glenn County CA est14_CA.txt 06NOV2015
06 23 27609 24659 30559 21.0 18.8 23.2 6137 5015 7259 23.9 19.5 28.3 4240 3438 5042 23.1 18.7 27.5 40581 38005 43157 Humboldt County CA est14_CA.txt 06NOV2015
06 25 40162 34718 45606 23.6 20.4 26.8 15870 13119 18621 31.3 25.9 36.7 11184 9112 13256 31.2 25.4 37.0 38737 35433 42041 Imperial County CA est14_CA.txt 06NOV2015
06 27 2533 2032 3034 14.0 11.2 16.8 761 584 938 20.2 15.5 24.9 494 367 621 18.6 13.8 23.4 49267 44287 54247 Inyo County CA est14_CA.txt 06NOV2015
06 29 206604 196231 216977 24.5 23.3 25.7 83543 78485 88601 32.9 30.9 34.9 57763 53963 61563 31.9 29.8 34.0 47451 45276 49626 Kern County CA est14_CA.txt 06NOV2015
06 31 33174 29471 36877 24.9 22.1 27.7 13840 12443 15237 33.8 30.4 37.2 9448 8406 10490 32.4 28.8 36.0 44490 40932 48048 Kings County CA est14_CA.txt 06NOV2015
06 33 15387 13523 17251 24.3 21.4 27.2 4119 3331 4907 32.3 26.1 38.5 2974 2425 3523 32.8 26.7 38.9 36333 33116 39550 Lake County CA est14_CA.txt 06NOV2015
06 35 4473 3526 5420 19.4 15.3 23.5 1069 827 1311 20.3 15.7 24.9 717 552 882 18.7 14.4 23.0 49995 45570 54420 Lassen County CA est14_CA.txt 06NOV2015
06 37 1863025 1823807 1902243 18.7 18.3 19.1 605129 588089 622169 26.7 25.9 27.5 429259 415920 442598 26.4 25.6 27.2 55686 55165 56207 Los Angeles County CA est14_CA.txt 06NOV2015
06 39 32542 27824 37260 22.3 19.1 25.5 12871 10728 15014 30.7 25.6 35.8 8619 7014 10224 28.4 23.1 33.7 43171 40100 46242 Madera County CA est14_CA.txt 06NOV2015
06 41 22272 19261 25283 8.8 7.6 10.0 5357 4413 6301 10.1 8.3 11.9 3467 2767 4167 8.6 6.9 10.3 94549 88283 100815 Marin County CA est14_CA.txt 06NOV2015
06 43 2830 2225 3435 16.2 12.7 19.7 726 554 898 25.0 19.1 30.9 518 393 643 24.3 18.4 30.2 47781 44401 51161 Mariposa County CA est14_CA.txt 06NOV2015
06 45 16256 13710 18802 18.8 15.9 21.7 4924 3897 5951 26.2 20.7 31.7 3270 2522 4018 24.5 18.9 30.1 42840 40000 45680 Mendocino County CA est14_CA.txt 06NOV2015
06 47 64585 59569 69601 24.8 22.9 26.7 28341 25868 30814 35.9 32.8 39.0 18269 16248 20290 31.8 28.3 35.3 43818 41284 46352 Merced County CA est14_CA.txt 06NOV2015
06 49 1770 1376 2164 20.2 15.7 24.7 544 420 668 31.3 24.1 38.5 369 280 458 28.3 21.5 35.1 39172 35813 42531 Modoc County CA est14_CA.txt 06NOV2015
06 51 1558 1199 1917 11.3 8.7 13.9 440 337 543 16.2 12.4 20.0 307 233 381 15.3 11.6 19.0 59181 53608 64754 Mono County CA est14_CA.txt 06NOV2015
06 53 70259 63656 76862 17.0 15.4 18.6 28122 25152 31092 25.2 22.5 27.9 18945 16774 21116 24.1 21.3 26.9 57428 55347 59509 Monterey County CA est14_CA.txt 06NOV2015
06 55 12317 10207 14427 9.0 7.5 10.5 3660 2849 4471 12.0 9.3 14.7 2558 1963 3153 11.2 8.6 13.8 71063 66853 75273 Napa County CA est14_CA.txt 06NOV2015
06 57 11193 9085 13301 11.4 9.2 13.6 3043 2413 3673 17.6 14.0 21.2 2164 1715 2613 16.6 13.2 20.0 57118 52704 61532 Nevada County CA est14_CA.txt 06NOV2015
06 59 400252 381547 418957 12.9 12.3 13.5 126952 118534 135370 17.9 16.7 19.1 89899 83584 96214 17.3 16.1 18.5 76061 74857 77265 Orange County CA est14_CA.txt 06NOV2015
06 61 30490 27114 33866 8.3 7.4 9.2 8188 6799 9577 9.7 8.1 11.3 5108 4039 6177 8.0 6.3 9.7 75689 73005 78373 Placer County CA est14_CA.txt 06NOV2015
06 63 2556 2009 3103 14.0 11.0 17.0 679 521 837 21.6 16.6 26.6 468 355 581 20.2 15.3 25.1 47964 43161 52767 Plumas County CA est14_CA.txt 06NOV2015
06 65 392706 372020 413392 17.1 16.2 18.0 141970 132470 151470 23.5 21.9 25.1 100349 93270 107428 22.5 20.9 24.1 56877 56024 57730 Riverside County CA est14_CA.txt 06NOV2015
06 67 264955 251180 278730 18.1 17.2 19.0 84938 78336 91540 23.8 21.9 25.7 57267 52354 62180 22.2 20.3 24.1 55803 54725 56881 Sacramento County CA est14_CA.txt 06NOV2015
06 69 8162 6885 9439 14.1 11.9 16.3 3056 2540 3572 19.8 16.5 23.1 2055 1681 2429 17.8 14.6 21.0 68166 63835 72497 San Benito County CA est14_CA.txt 06NOV2015
06 71 422405 403202 441608 20.4 19.5 21.3 159554 150886 168222 28.2 26.7 29.7 113001 106473 119529 27.4 25.8 29.0 51951 51101 52801 San Bernardino County CA est14_CA.txt 06NOV2015
06 73 467248 448710 485786 14.7 14.1 15.3 135884 127529 144239 18.9 17.7 20.1 93941 87441 100441 18.6 17.3 19.9 66034 65066 67002 San Diego County CA est14_CA.txt 06NOV2015
06 75 101313 94708 107918 12.1 11.3 12.9 15224 12388 18060 13.6 11.1 16.1 11094 9016 13172 15.2 12.3 18.1 83788 81114 86462 San Francisco County CA est14_CA.txt 06NOV2015
06 77 145167 135863 154471 20.7 19.4 22.0 53907 49345 58469 27.5 25.2 29.8 38015 34616 41414 26.5 24.1 28.9 51527 50269 52785 San Joaquin County CA est14_CA.txt 06NOV2015
06 79 38048 33782 42314 14.5 12.9 16.1 7765 6329 9201 15.6 12.7 18.5 5259 4194 6324 14.5 11.6 17.4 61775 58599 64951 San Luis Obispo County CA est14_CA.txt 06NOV2015
06 81 56580 50164 62996 7.5 6.6 8.4 15725 13131 18319 9.8 8.2 11.4 10911 9014 12808 9.5 7.8 11.2 100806 99503 102109 San Mateo County CA est14_CA.txt 06NOV2015
06 83 73600 67362 79838 17.4 15.9 18.9 21781 19117 24445 22.6 19.8 25.4 14859 12972 16746 21.7 18.9 24.5 62116 59007 65225 Santa Barbara County CA est14_CA.txt 06NOV2015
06 85 159553 146664 172442 8.5 7.8 9.2 40118 34171 46065 9.3 7.9 10.7 27769 23521 32017 8.9 7.5 10.3 97219 95336 99102 Santa Clara County CA est14_CA.txt 06NOV2015
06 87 42076 37951 46201 16.1 14.5 17.7 10217 8573 11861 19.1 16.0 22.2 7149 5982 8316 18.6 15.6 21.6 64257 59903 68611 Santa Cruz County CA est14_CA.txt 06NOV2015
06 89 26016 22460 29572 14.7 12.7 16.7 7682 5893 9471 20.3 15.6 25.0 5411 4116 6706 19.7 15.0 24.4 43661 41361 45961 Shasta County CA est14_CA.txt 06NOV2015
06 91 409 314 504 13.8 10.6 17.0 88 67 109 19.0 14.5 23.5 60 45 75 16.7 12.6 20.8 47293 42283 52303 Sierra County CA est14_CA.txt 06NOV2015
06 93 9076 7936 10216 21.1 18.5 23.7 2646 2170 3122 30.3 24.8 35.8 1811 1456 2166 28.4 22.8 34.0 38641 35758 41524 Siskiyou County CA est14_CA.txt 06NOV2015
06 95 51638 45698 57578 12.3 10.9 13.7 16144 13601 18687 16.5 13.9 19.1 10742 8906 12578 15.0 12.4 17.6 67106 63857 70355 Solano County CA est14_CA.txt 06NOV2015
06 97 55742 50076 61408 11.3 10.1 12.5 13770 11378 16162 13.6 11.2 16.0 9529 7771 11287 12.7 10.3 15.1 66949 64082 69816 Sonoma County CA est14_CA.txt 06NOV2015
06 99 95456 86552 104360 18.1 16.4 19.8 34198 30197 38199 23.8 21.0 26.6 23015 19904 26126 22.0 19.0 25.0 50917 49680 52154 Stanislaus County CA est14_CA.txt 06NOV2015
06 101 14485 11860 17110 15.2 12.4 18.0 5200 4022 6378 20.8 16.1 25.5 3584 2735 4433 19.3 14.7 23.9 51827 48680 54974 Sutter County CA est14_CA.txt 06NOV2015
06 103 11358 9200 13516 18.2 14.7 21.7 3956 3041 4871 26.7 20.5 32.9 2703 2044 3362 24.8 18.8 30.8 40782 37503 44061 Tehama County CA est14_CA.txt 06NOV2015
06 105 2577 2002 3152 19.9 15.5 24.3 684 522 846 31.7 24.2 39.2 464 351 577 30.8 23.3 38.3 34961 31947 37975 Trinity County CA est14_CA.txt 06NOV2015
06 107 127305 118339 136271 28.1 26.1 30.1 52542 47523 57561 36.7 33.2 40.2 37023 33259 40787 36.1 32.4 39.8 42360 40429 44291 Tulare County CA est14_CA.txt 06NOV2015
06 109 7177 5823 8531 14.3 11.6 17.0 1813 1392 2234 20.5 15.7 25.3 1239 944 1534 18.9 14.4 23.4 49476 45216 53736 Tuolumne County CA est14_CA.txt 06NOV2015
06 111 95912 86338 105486 11.5 10.4 12.6 31764 27476 36052 15.8 13.7 17.9 21410 18281 24539 14.5 12.4 16.6 74967 73152 76782 Ventura County CA est14_CA.txt 06NOV2015
06 113 39493 36197 42789 19.5 17.9 21.1 7788 6415 9161 17.5 14.4 20.6 5304 4297 6311 16.4 13.3 19.5 54509 51187 57831 Yolo County CA est14_CA.txt 06NOV2015
06 115 15693 13360 18026 21.6 18.4 24.8 5802 4777 6827 28.6 23.6 33.6 3802 3006 4598 26.6 21.0 32.2 41403 37739 45067 Yuba County CA est14_CA.txt 06NOV2015
19 changes: 19 additions & 0 deletions poverty/src/poverty/County.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package poverty;

public class County {

public String name;
public String pov_percent;
public String pov_count;
public String med_income;

public County(String line) {
this.name = line.substring(193, 238);

Choose a reason for hiding this comment

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

Nitpick - since the file format could at some point change, might recommend setting these ints as constants which would map to the type of data they are associated with

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good, updated


String[] details = line.split("\\s+");
this.pov_percent = details[11];
this.pov_count = details[8];
this.med_income = details[20];
}

}
51 changes: 51 additions & 0 deletions poverty/src/poverty/Program.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package poverty;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Program {
public static void main(String[] args) {
System.out.println("Welcome to the CA/WA Poverty Educator!");
Scanner scan = new Scanner(System.in);
// capture user input for state
System.out.print("Enter 'CA' for California or 'WA' for Washington: ");
String state = scan.nextLine().toUpperCase();
// use appropriate file based on user state selection
File file = null;
if(state.equals("WA")) {
file = new File("washington.txt");
} else if(state.equals("CA")){

Choose a reason for hiding this comment

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

What about some other state's input?

Copy link
Author

Choose a reason for hiding this comment

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

I added an if statement to handle other input besides WA and CA. (this might change to a while loop to allow users to keep trying until they get it right)

file = new File("california.txt");
}
try {
Scanner scanner = new Scanner(file);
// capture user input for county
System.out.print("Enter a county in " + state + ": ");
String county = scan.nextLine();
scan.close();
// find and print the line matching the county entered by user
String line;
boolean no_county = true;

Choose a reason for hiding this comment

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

Don't forget about your Java naming conventions, this one should be noCounty

Copy link
Author

Choose a reason for hiding this comment

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

Updated

while (scanner.hasNextLine()) {
line = scanner.nextLine();

if(line.toLowerCase().contains(county.toLowerCase())) {
County user_county = new County(line);
System.out.println("County: " + user_county.name );
System.out.println("Percentage of children in poverty: " + user_county.pov_percent);
System.out.println("Number of children in poverty: " + user_county.pov_count);
System.out.println("Median household income: "+ user_county.med_income);
no_county = false;
}
}
scanner.close();
if(no_county) {

Choose a reason for hiding this comment

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

A better name for this variable might be something like countyFound

Copy link
Author

Choose a reason for hiding this comment

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

Updated

System.out.println("Invalid county for " + state);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}

}
}
Loading