From 18c1ec8acaaae5a1731cc01d25d417029ef1c007 Mon Sep 17 00:00:00 2001 From: Kelly Date: Tue, 5 Apr 2016 15:19:44 -0700 Subject: [PATCH 01/45] create gitignore and county and program class files --- .gitignore | 50 ++++++++++++++++++++++++++++++++ poverty/src/poverty/County.java | 5 ++++ poverty/src/poverty/Program.java | 10 +++++++ 3 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 poverty/src/poverty/County.java create mode 100644 poverty/src/poverty/Program.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c8c53c --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java new file mode 100644 index 0000000..91313eb --- /dev/null +++ b/poverty/src/poverty/County.java @@ -0,0 +1,5 @@ +package poverty; + +public class County { + +} diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java new file mode 100644 index 0000000..6376067 --- /dev/null +++ b/poverty/src/poverty/Program.java @@ -0,0 +1,10 @@ +package poverty; + +public class Program { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + } + +} From 69dd1c4983078b824c400e22d6debb1f530bed26 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 09:32:09 -0700 Subject: [PATCH 02/45] program captures user input --- poverty/src/poverty/Program.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 6376067..4ef5f1f 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -1,10 +1,14 @@ package poverty; -public class Program { - - public static void main(String[] args) { - // TODO Auto-generated method stub +import java.util.Scanner; +public class Program { + public static void main(String[] args) { + System.out.println("Welcome to Poverty Educator!"); + System.out.print("Enter a U.S. county to learn about: "); + Scanner scan = new Scanner(System.in); + String county = scan.nextLine(); + System.out.println("County: "+ county); + scan.close(); } - } From ba3dfa16eb99130edecbf55b3242bd1dea38e7be Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 09:41:19 -0700 Subject: [PATCH 03/45] update prompt --- poverty/src/poverty/Program.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 4ef5f1f..efcf6c0 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -4,8 +4,8 @@ public class Program { public static void main(String[] args) { - System.out.println("Welcome to Poverty Educator!"); - System.out.print("Enter a U.S. county to learn about: "); + System.out.println("Welcome to CA/WA Poverty Educator!"); + System.out.print("Enter a county in either California or Washington: "); Scanner scan = new Scanner(System.in); String county = scan.nextLine(); System.out.println("County: "+ county); From 464d2fe9ef65a915f0dc1f346983d11432840b2f Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 10:02:30 -0700 Subject: [PATCH 04/45] add wa txt file, program is able to read first line from it --- poverty/src/poverty/Program.java | 14 +++++++++++ poverty/washington.txt | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 poverty/washington.txt diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index efcf6c0..4a31b00 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -1,5 +1,7 @@ package poverty; +import java.io.File; +import java.io.FileNotFoundException; import java.util.Scanner; public class Program { @@ -10,5 +12,17 @@ public static void main(String[] args) { String county = scan.nextLine(); System.out.println("County: "+ county); scan.close(); + + File washington = new File("washington.txt"); + + try { + Scanner scanner = new Scanner(washington); + String line = scanner.nextLine(); + System.out.println("Data: " + line); + scanner.close(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } } diff --git a/poverty/washington.txt b/poverty/washington.txt new file mode 100644 index 0000000..77bb19a --- /dev/null +++ b/poverty/washington.txt @@ -0,0 +1,40 @@ +53 0 913463 895355 931571 13.2 12.9 13.5 275662 265882 285442 17.5 16.9 18.1 180464 171990 188938 16.0 15.2 16.8 61358 60882 61834 85453 80800 90106 19.6 18.5 20.7 Washington WA est14_WA.txt 06NOV2015 +53 1 3598 2947 4249 19.0 15.6 22.4 1816 1477 2155 27.1 22.0 32.2 1152 903 1401 24.7 19.4 30.0 47423 42474 52372 Adams County WA est14_WA.txt 06NOV2015 +53 3 3573 2849 4297 16.3 13.0 19.6 1104 846 1362 24.2 18.5 29.9 723 546 900 21.5 16.2 26.8 44055 39944 48166 Asotin County WA est14_WA.txt 06NOV2015 +53 5 26893 23628 30158 14.6 12.8 16.4 10421 8839 12003 21.3 18.1 24.5 6754 5615 7893 19.0 15.8 22.2 58750 56072 61428 Benton County WA est14_WA.txt 06NOV2015 +53 7 10298 8470 12126 14.0 11.5 16.5 3588 2774 4402 20.2 15.6 24.8 2436 1839 3033 19.2 14.5 23.9 49174 45028 53320 Chelan County WA est14_WA.txt 06NOV2015 +53 9 11518 9848 13188 16.2 13.8 18.6 3267 2671 3863 26.2 21.4 31.0 2025 1593 2457 22.3 17.5 27.1 47185 43543 50827 Clallam County WA est14_WA.txt 06NOV2015 +53 11 44213 38703 49723 9.9 8.7 11.1 15179 12259 18099 13.6 11.0 16.2 10647 8436 12858 12.8 10.2 15.4 61747 60396 63098 Clark County WA est14_WA.txt 06NOV2015 +53 13 607 469 745 15.5 12.0 19.0 190 145 235 25.7 19.6 31.8 130 98 162 22.0 16.6 27.4 45465 41255 49675 Columbia County WA est14_WA.txt 06NOV2015 +53 15 20701 18425 22977 20.6 18.3 22.9 6118 5100 7136 26.8 22.3 31.3 3909 3166 4652 23.1 18.7 27.5 44235 41355 47115 Cowlitz County WA est14_WA.txt 06NOV2015 +53 17 6120 4978 7262 15.5 12.6 18.4 2507 1974 3040 24.4 19.2 29.6 1712 1339 2085 22.7 17.8 27.6 51151 47257 55045 Douglas County WA est14_WA.txt 06NOV2015 +53 19 1700 1392 2008 22.4 18.3 26.5 403 316 490 29.1 22.8 35.4 264 205 323 25.9 20.1 31.7 39992 36038 43946 Ferry County WA est14_WA.txt 06NOV2015 +53 21 14661 12404 16918 17.3 14.6 20.0 7214 6027 8401 24.9 20.8 29.0 4533 3611 5455 22.4 17.8 27.0 55006 51191 58821 Franklin County WA est14_WA.txt 06NOV2015 +53 23 310 240 380 14.2 11.0 17.4 91 70 112 20.7 15.8 25.6 60 45 75 17.4 13.1 21.7 46404 41508 51300 Garfield County WA est14_WA.txt 06NOV2015 +53 25 14508 11796 17220 15.8 12.8 18.8 5766 4441 7091 20.9 16.1 25.7 3918 2983 4853 20.0 15.2 24.8 50388 47611 53165 Grant County WA est14_WA.txt 06NOV2015 +53 27 13322 11257 15387 19.6 16.6 22.6 4146 3376 4916 28.6 23.3 33.9 2760 2199 3321 26.3 21.0 31.6 43205 40965 45445 Grays Harbor County WA est14_WA.txt 06NOV2015 +53 29 7964 6639 9289 10.3 8.6 12.0 2267 1801 2733 15.4 12.2 18.6 1514 1190 1838 14.7 11.6 17.8 59358 55827 62889 Island County WA est14_WA.txt 06NOV2015 +53 31 4183 3445 4921 14.1 11.6 16.6 972 770 1174 24.5 19.4 29.6 643 502 784 21.8 17.0 26.6 50964 46641 55287 Jefferson County WA est14_WA.txt 06NOV2015 +53 33 230750 218081 243419 11.3 10.7 11.9 58351 52757 63945 13.6 12.3 14.9 38527 34470 42584 12.8 11.5 14.1 75738 74417 77059 King County WA est14_WA.txt 06NOV2015 +53 35 27550 23819 31281 11.2 9.7 12.7 7473 6103 8843 14.4 11.8 17.0 4593 3607 5579 12.2 9.6 14.8 61898 59584 64212 Kitsap County WA est14_WA.txt 06NOV2015 +53 37 7459 6329 8589 18.6 15.8 21.4 1410 1105 1715 18.7 14.7 22.7 953 742 1164 17.6 13.7 21.5 48127 44926 51328 Kittitas County WA est14_WA.txt 06NOV2015 +53 39 3029 2365 3693 14.6 11.4 17.8 935 713 1157 22.6 17.2 28.0 641 481 801 20.9 15.7 26.1 49348 44723 53973 Klickitat County WA est14_WA.txt 06NOV2015 +53 41 12695 10463 14927 17.1 14.1 20.1 3912 3075 4749 24.5 19.3 29.7 2600 2017 3183 22.3 17.3 27.3 44243 40710 47776 Lewis County WA est14_WA.txt 06NOV2015 +53 43 1274 1002 1546 12.5 9.8 15.2 392 303 481 17.7 13.7 21.7 269 207 331 15.7 12.1 19.3 49955 45180 54730 Lincoln County WA est14_WA.txt 06NOV2015 +53 45 9040 7636 10444 15.6 13.2 18.0 2660 2093 3227 23.6 18.6 28.6 1805 1406 2204 22.4 17.4 27.4 52313 49305 55321 Mason County WA est14_WA.txt 06NOV2015 +53 47 9427 8024 10830 23.2 19.8 26.6 2969 2411 3527 31.5 25.6 37.4 1992 1578 2406 29.5 23.4 35.6 37782 34745 40819 Okanogan County WA est14_WA.txt 06NOV2015 +53 49 3606 2929 4283 17.8 14.5 21.1 965 775 1155 28.8 23.1 34.5 674 538 810 28.0 22.4 33.6 40189 36441 43937 Pacific County WA est14_WA.txt 06NOV2015 +53 51 2868 2398 3338 22.3 18.6 26.0 842 665 1019 33.1 26.2 40.0 588 463 713 30.2 23.8 36.6 42579 38373 46785 Pend Oreille County WA est14_WA.txt 06NOV2015 +53 53 106432 97890 114974 13.1 12.1 14.1 34165 30111 38219 17.5 15.4 19.6 22439 19462 25416 16.2 14.1 18.3 60397 58946 61848 Pierce County WA est14_WA.txt 06NOV2015 +53 55 2018 1729 2307 12.7 10.9 14.5 437 351 523 19.6 15.7 23.5 290 227 353 16.7 13.1 20.3 54721 50513 58929 San Juan County WA est14_WA.txt 06NOV2015 +53 57 18627 16409 20845 15.7 13.8 17.6 6124 5231 7017 23.2 19.8 26.6 3765 3106 4424 19.8 16.3 23.3 51395 48709 54081 Skagit County WA est14_WA.txt 06NOV2015 +53 59 1421 1099 1743 12.6 9.7 15.5 467 353 581 20.1 15.2 25.0 316 235 397 17.5 13.0 22.0 52673 47473 57873 Skamania County WA est14_WA.txt 06NOV2015 +53 61 73930 66931 80929 9.9 9.0 10.8 22598 19490 25706 13.1 11.3 14.9 14401 12105 16697 11.5 9.7 13.3 71890 70201 73579 Snohomish County WA est14_WA.txt 06NOV2015 +53 63 76910 70461 83359 16.3 14.9 17.7 21892 18858 24926 20.5 17.7 23.3 13976 11760 16192 18.2 15.3 21.1 50083 48190 51976 Spokane County WA est14_WA.txt 06NOV2015 +53 65 8368 7255 9481 19.3 16.7 21.9 2668 2169 3167 28.2 22.9 33.5 1773 1413 2133 24.5 19.5 29.5 43823 40849 46797 Stevens County WA est14_WA.txt 06NOV2015 +53 67 31197 27796 34598 11.9 10.6 13.2 9031 7502 10560 15.6 13.0 18.2 5706 4551 6861 13.7 10.9 16.5 61653 59047 64259 Thurston County WA est14_WA.txt 06NOV2015 +53 69 558 431 685 13.9 10.7 17.1 184 141 227 26.7 20.4 33.0 130 98 162 24.3 18.3 30.3 51022 48377 53667 Wahkiakum County WA est14_WA.txt 06NOV2015 +53 71 8682 7030 10334 15.7 12.7 18.7 2654 2046 3262 20.8 16.0 25.6 1762 1341 2183 19.1 14.6 23.6 49819 46459 53179 Walla Walla County WA est14_WA.txt 06NOV2015 +53 73 31842 28461 35223 15.7 14.0 17.4 7304 6146 8462 17.7 14.9 20.5 4888 4054 5722 16.4 13.6 19.2 53733 51153 56313 Whatcom County WA est14_WA.txt 06NOV2015 +53 75 11567 10634 12500 28.4 26.1 30.7 1181 938 1424 16.7 13.3 20.1 704 529 879 14.6 11.0 18.2 41837 37907 45767 Whitman County WA est14_WA.txt 06NOV2015 +53 77 50044 45009 55079 20.5 18.4 22.6 22000 19457 24543 30.3 26.8 33.8 14492 12596 16388 28.0 24.3 31.7 44342 42101 46583 Yakima County WA est14_WA.txt 06NOV2015 From a14c0f03e7fb34073a14f5b54c50c376d8b82e3c Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 10:23:49 -0700 Subject: [PATCH 05/45] program can print a specific line --- poverty/src/poverty/Program.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 4a31b00..192121d 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -17,8 +17,16 @@ public static void main(String[] args) { try { Scanner scanner = new Scanner(washington); - String line = scanner.nextLine(); - System.out.println("Data: " + line); + int lineNum = 0; + String line; + while (scanner.hasNextLine()) { + line = scanner.nextLine(); + lineNum++; + + if(lineNum == 2) { + System.out.println("Line contents: " + line); + } + } scanner.close(); } catch (FileNotFoundException e) { e.printStackTrace(); From 9899562a201f11e04b6fabcced05f31bf3382e22 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 10:40:58 -0700 Subject: [PATCH 06/45] program successfully finds line matching user input --- poverty/src/poverty/Program.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 192121d..a6071af 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -18,12 +18,13 @@ public static void main(String[] args) { try { Scanner scanner = new Scanner(washington); int lineNum = 0; - String line; + String line; while (scanner.hasNextLine()) { line = scanner.nextLine(); lineNum++; - if(lineNum == 2) { + if(line.toLowerCase().contains(county.toLowerCase())) { + System.out.println("Line num: " + lineNum); System.out.println("Line contents: " + line); } } From fcac531d6ff405bf33f00f72a447f15355cb447d Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:17:42 -0700 Subject: [PATCH 07/45] add california txt file, user can choose state and county and program prints line from txt file if county is found --- poverty/California.txt | 59 ++++++++++++++++++++++++++++++++ poverty/src/poverty/Program.java | 29 +++++++++++----- 2 files changed, 80 insertions(+), 8 deletions(-) create mode 100644 poverty/California.txt diff --git a/poverty/California.txt b/poverty/California.txt new file mode 100644 index 0000000..01adc29 --- /dev/null +++ b/poverty/California.txt @@ -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 diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index a6071af..45447d4 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -7,18 +7,27 @@ public class Program { public static void main(String[] args) { System.out.println("Welcome to CA/WA Poverty Educator!"); - System.out.print("Enter a county in either California or Washington: "); Scanner scan = new Scanner(System.in); - String county = scan.nextLine(); - System.out.println("County: "+ county); - scan.close(); - - File washington = new File("washington.txt"); - + // 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")){ + file = new File("california.txt"); + } try { - Scanner scanner = new Scanner(washington); + 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 int lineNum = 0; String line; + boolean no_county = true; while (scanner.hasNextLine()) { line = scanner.nextLine(); lineNum++; @@ -26,9 +35,13 @@ public static void main(String[] args) { if(line.toLowerCase().contains(county.toLowerCase())) { System.out.println("Line num: " + lineNum); System.out.println("Line contents: " + line); + no_county = false; } } scanner.close(); + if(no_county) { + System.out.println("Invalid county for " + state); + } } catch (FileNotFoundException e) { e.printStackTrace(); } From 91ff5148e9baf7372925739d61ccde4d80b89374 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:21:28 -0700 Subject: [PATCH 08/45] update prompt --- poverty/src/poverty/Program.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 45447d4..c9f991a 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -6,7 +6,7 @@ public class Program { public static void main(String[] args) { - System.out.println("Welcome to CA/WA Poverty Educator!"); + 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: "); From dfba9321f85ae2b8ccbb21a22d35cf71d5c0eb2b Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:27:34 -0700 Subject: [PATCH 09/45] add system output describing relevant county info --- poverty/src/poverty/Program.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index c9f991a..c607eee 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -35,6 +35,12 @@ public static void main(String[] args) { if(line.toLowerCase().contains(county.toLowerCase())) { System.out.println("Line num: " + lineNum); System.out.println("Line contents: " + line); + + //the median household income. + System.out.println("County: "); + System.out.println("Percentage of children in poverty: "); + System.out.println("Number of children in poverty: "); + System.out.println("Median household income: "); no_county = false; } } From ab8759ebed480f617fdbaac72eb3d4b9ab1f552f Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:31:42 -0700 Subject: [PATCH 10/45] add constructor to county class, program creates new county object if county is found --- poverty/src/poverty/County.java | 4 ++++ poverty/src/poverty/Program.java | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index 91313eb..ada3dd9 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -2,4 +2,8 @@ public class County { + public County(int line_num) { + // TODO Auto-generated constructor stub + } + } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index c607eee..0f9fe7b 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -25,18 +25,19 @@ public static void main(String[] args) { String county = scan.nextLine(); scan.close(); // find and print the line matching the county entered by user - int lineNum = 0; + int line_num = 0; String line; boolean no_county = true; while (scanner.hasNextLine()) { line = scanner.nextLine(); - lineNum++; + line_num++; if(line.toLowerCase().contains(county.toLowerCase())) { - System.out.println("Line num: " + lineNum); + System.out.println("Line num: " + line_num); System.out.println("Line contents: " + line); //the median household income. + County user_county = new County(line_num); System.out.println("County: "); System.out.println("Percentage of children in poverty: "); System.out.println("Number of children in poverty: "); From fe894ff97515e962ea896b911e794276c97043e0 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:43:15 -0700 Subject: [PATCH 11/45] add file to county class constructor --- poverty/src/poverty/County.java | 4 +++- poverty/src/poverty/Program.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index ada3dd9..bbf1f59 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -1,8 +1,10 @@ package poverty; +import java.io.File; + public class County { - public County(int line_num) { + public County(File file, int line_num) { // TODO Auto-generated constructor stub } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 0f9fe7b..25cc19b 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -37,7 +37,7 @@ public static void main(String[] args) { System.out.println("Line contents: " + line); //the median household income. - County user_county = new County(line_num); + County user_county = new County(file, line_num); System.out.println("County: "); System.out.println("Percentage of children in poverty: "); System.out.println("Number of children in poverty: "); From 791071467d3e1f1baf028f613f3b2220535c0238 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 14:46:06 -0700 Subject: [PATCH 12/45] remove line_num variable, change county class constructor to take in line as parameter --- poverty/src/poverty/County.java | 4 +--- poverty/src/poverty/Program.java | 5 +---- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index bbf1f59..e756233 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -1,10 +1,8 @@ package poverty; -import java.io.File; - public class County { - public County(File file, int line_num) { + public County(String line) { // TODO Auto-generated constructor stub } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 25cc19b..6eac49f 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -25,19 +25,16 @@ public static void main(String[] args) { String county = scan.nextLine(); scan.close(); // find and print the line matching the county entered by user - int line_num = 0; String line; boolean no_county = true; while (scanner.hasNextLine()) { line = scanner.nextLine(); - line_num++; if(line.toLowerCase().contains(county.toLowerCase())) { - System.out.println("Line num: " + line_num); System.out.println("Line contents: " + line); //the median household income. - County user_county = new County(file, line_num); + County user_county = new County(line); System.out.println("County: "); System.out.println("Percentage of children in poverty: "); System.out.println("Number of children in poverty: "); From 2578d3584158ef035bdea0aed4b8095a095063db Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 15:01:48 -0700 Subject: [PATCH 13/45] poverty percent is an attribute of county, program outputs this value for user selected county --- poverty/src/poverty/County.java | 5 ++++- poverty/src/poverty/Program.java | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index e756233..a7aa5c0 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -2,8 +2,11 @@ public class County { + public String pov_percent; + public County(String line) { - // TODO Auto-generated constructor stub + String[] details = line.split("\\s+"); + this.pov_percent = details[11]; } } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 6eac49f..1a06699 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -35,8 +35,8 @@ public static void main(String[] args) { //the median household income. County user_county = new County(line); - System.out.println("County: "); - System.out.println("Percentage of children in poverty: "); + System.out.println("County: " ); + System.out.println("Percentage of children in poverty: "+ user_county.pov_percent); System.out.println("Number of children in poverty: "); System.out.println("Median household income: "); no_county = false; From 8d7199885f8ea36d824da7d5ab7e679db58a40b1 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 15:06:52 -0700 Subject: [PATCH 14/45] program displays number of children in poverty and median household income for selected county --- poverty/src/poverty/County.java | 7 ++++++- poverty/src/poverty/Program.java | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index a7aa5c0..6cf3bb3 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -1,12 +1,17 @@ package poverty; public class County { - + + public String name; public String pov_percent; + public String pov_count; + public String med_income; public County(String line) { String[] details = line.split("\\s+"); this.pov_percent = details[11]; + this.pov_count = details[8]; + this.med_income = details[20]; } } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 1a06699..4dc66c3 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -36,9 +36,9 @@ public static void main(String[] args) { //the median household income. County user_county = new County(line); System.out.println("County: " ); - System.out.println("Percentage of children in poverty: "+ user_county.pov_percent); - System.out.println("Number of children in poverty: "); - System.out.println("Median household income: "); + 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; } } From a7bafbf9d7cd4b67b9f981d6b9b762ff078427d9 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 15:09:44 -0700 Subject: [PATCH 15/45] program displays required info for user selected county --- poverty/src/poverty/County.java | 2 ++ poverty/src/poverty/Program.java | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index 6cf3bb3..3f527fe 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -8,6 +8,8 @@ public class County { public String med_income; public County(String line) { + this.name = line.substring(193, 238); + String[] details = line.split("\\s+"); this.pov_percent = details[11]; this.pov_count = details[8]; diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 4dc66c3..205f2c0 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -30,12 +30,9 @@ public static void main(String[] args) { while (scanner.hasNextLine()) { line = scanner.nextLine(); - if(line.toLowerCase().contains(county.toLowerCase())) { - System.out.println("Line contents: " + line); - - //the median household income. + if(line.toLowerCase().contains(county.toLowerCase())) { County user_county = new County(line); - System.out.println("County: " ); + 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); From bec19c862241a0b6ef700fbac05fb6413e146913 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 18:02:33 -0700 Subject: [PATCH 16/45] handle other states and other input besides wa and ca --- poverty/src/poverty/Program.java | 56 +++++++++++++++++--------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 205f2c0..7a775fa 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -18,33 +18,37 @@ public static void main(String[] args) { } else if(state.equals("CA")){ 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; - 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; - } + if(file != null) { + 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; + 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) { + System.out.println("Invalid county for " + state); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); } - scanner.close(); - if(no_county) { - System.out.println("Invalid county for " + state); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); + } else { + System.out.println("Invalid state."); } } From 1d2e7ad6c4444bf6f2d58184955aae4f67191330 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 18:07:19 -0700 Subject: [PATCH 17/45] change no_county variable to countyFound --- poverty/src/poverty/Program.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 7a775fa..998a989 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -27,7 +27,7 @@ public static void main(String[] args) { scan.close(); // find and print the line matching the county entered by user String line; - boolean no_county = true; + boolean countyFound = false; while (scanner.hasNextLine()) { line = scanner.nextLine(); @@ -37,11 +37,11 @@ public static void main(String[] args) { 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; + countyFound = true; } } scanner.close(); - if(no_county) { + if(!countyFound) { System.out.println("Invalid county for " + state); } } catch (FileNotFoundException e) { From 918960cc32b326f06068ee41e02d116a897a1929 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 18:09:30 -0700 Subject: [PATCH 18/45] change user_county to userCounty --- poverty/src/poverty/Program.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 998a989..a5677fb 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -32,11 +32,11 @@ public static void main(String[] args) { 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); + County userCounty = new County(line); + System.out.println("County: " + userCounty.name ); + System.out.println("Percentage of children in poverty: " + userCounty.pov_percent); + System.out.println("Number of children in poverty: " + userCounty.pov_count); + System.out.println("Median household income: "+ userCounty.med_income); countyFound = true; } } From 3a5c9086ba2165e192039648420ceac67b04b057 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 18:12:14 -0700 Subject: [PATCH 19/45] change county attribute variable names to lower camel case --- poverty/src/poverty/County.java | 12 ++++++------ poverty/src/poverty/Program.java | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index 3f527fe..c342174 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -3,17 +3,17 @@ public class County { public String name; - public String pov_percent; - public String pov_count; - public String med_income; + public String povPercent; + public String povCount; + public String medIncome; public County(String line) { this.name = line.substring(193, 238); String[] details = line.split("\\s+"); - this.pov_percent = details[11]; - this.pov_count = details[8]; - this.med_income = details[20]; + this.povPercent = details[11]; + this.povCount = details[8]; + this.medIncome = details[20]; } } diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index a5677fb..951952a 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -34,9 +34,9 @@ public static void main(String[] args) { if(line.toLowerCase().contains(county.toLowerCase())) { County userCounty = new County(line); System.out.println("County: " + userCounty.name ); - System.out.println("Percentage of children in poverty: " + userCounty.pov_percent); - System.out.println("Number of children in poverty: " + userCounty.pov_count); - System.out.println("Median household income: "+ userCounty.med_income); + System.out.println("Percentage of children in poverty: " + userCounty.povPercent); + System.out.println("Number of children in poverty: " + userCounty.povCount); + System.out.println("Median household income: "+ userCounty.medIncome); countyFound = true; } } From 74e7e314eef325c059124994bb112c0c4994c672 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 6 Apr 2016 18:17:39 -0700 Subject: [PATCH 20/45] make name name column index range constants --- poverty/src/poverty/County.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/poverty/src/poverty/County.java b/poverty/src/poverty/County.java index c342174..3f419ec 100644 --- a/poverty/src/poverty/County.java +++ b/poverty/src/poverty/County.java @@ -1,6 +1,8 @@ package poverty; public class County { + final int NAME_START = 193; + final int NAME_END = 238; public String name; public String povPercent; @@ -8,7 +10,7 @@ public class County { public String medIncome; public County(String line) { - this.name = line.substring(193, 238); + this.name = line.substring(NAME_START, NAME_END); String[] details = line.split("\\s+"); this.povPercent = details[11]; From e1a47bc0be14535fc64330e7cf60b65aff3e156d Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 09:58:51 -0700 Subject: [PATCH 21/45] user input for state in a while loop --- poverty/src/poverty/Program.java | 79 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 951952a..e2d082e 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -8,47 +8,48 @@ 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")){ - file = new File("california.txt"); - } - if(file != null) { - 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 countyFound = false; - while (scanner.hasNextLine()) { - line = scanner.nextLine(); - - if(line.toLowerCase().contains(county.toLowerCase())) { - County userCounty = new County(line); - System.out.println("County: " + userCounty.name ); - System.out.println("Percentage of children in poverty: " + userCounty.povPercent); - System.out.println("Number of children in poverty: " + userCounty.povCount); - System.out.println("Median household income: "+ userCounty.medIncome); - countyFound = true; - } - } - scanner.close(); - if(!countyFound) { - System.out.println("Invalid county for " + state); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); + String state = null; + while(file == null) { + // capture user input for state + System.out.print("Enter 'CA' for California or 'WA' for Washington: "); + state = scan.nextLine().toUpperCase(); + // use appropriate file based on user state selection + if(state.equals("WA")) { + file = new File("washington.txt"); + } else if(state.equals("CA")){ + 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 countyFound = false; + while (scanner.hasNextLine()) { + line = scanner.nextLine(); + + if(line.toLowerCase().contains(county.toLowerCase())) { + County userCounty = new County(line); + System.out.println("County: " + userCounty.name ); + System.out.println("Percentage of children in poverty: " + userCounty.povPercent); + System.out.println("Number of children in poverty: " + userCounty.povCount); + System.out.println("Median household income: "+ userCounty.medIncome); + countyFound = true; + } } - } else { - System.out.println("Invalid state."); + scanner.close(); + if(!countyFound) { + System.out.println("Invalid county for " + state); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); } } From e4ea2cba39b4b5cfc6a5225303c57913588861ad Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:10:55 -0700 Subject: [PATCH 22/45] rename scanner variables --- poverty/src/poverty/Program.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index e2d082e..21680cd 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -7,33 +7,33 @@ 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); + Scanner scanInput = new Scanner(System.in); File file = null; String state = null; while(file == null) { // capture user input for state System.out.print("Enter 'CA' for California or 'WA' for Washington: "); - state = scan.nextLine().toUpperCase(); + state = scanInput.nextLine().toUpperCase(); // use appropriate file based on user state selection if(state.equals("WA")) { file = new File("washington.txt"); } else if(state.equals("CA")){ file = new File("california.txt"); } - } + } try { - Scanner scanner = new Scanner(file); + Scanner scanFile = new Scanner(file); // capture user input for county System.out.print("Enter a county in " + state + ": "); - String county = scan.nextLine(); - scan.close(); + String county = scanInput.nextLine(); + scanInput.close(); // find and print the line matching the county entered by user String line; boolean countyFound = false; - while (scanner.hasNextLine()) { - line = scanner.nextLine(); + while (scanFile.hasNextLine()) { + line = scanFile.nextLine(); if(line.toLowerCase().contains(county.toLowerCase())) { County userCounty = new County(line); @@ -44,7 +44,7 @@ public static void main(String[] args) { countyFound = true; } } - scanner.close(); + scanFile.close(); if(!countyFound) { System.out.println("Invalid county for " + state); } From c68e21d1762e9e9e2d239aaf8b5a617ce136e846 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:13:58 -0700 Subject: [PATCH 23/45] move close of scanInput to end of method --- poverty/src/poverty/Program.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 21680cd..26f35f2 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -28,7 +28,6 @@ public static void main(String[] args) { // capture user input for county System.out.print("Enter a county in " + state + ": "); String county = scanInput.nextLine(); - scanInput.close(); // find and print the line matching the county entered by user String line; boolean countyFound = false; @@ -51,6 +50,6 @@ public static void main(String[] args) { } catch (FileNotFoundException e) { e.printStackTrace(); } - + scanInput.close(); } } From 2babb5c9efefb85ddaa3fd50efe74d61d2f9ed4f Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:16:35 -0700 Subject: [PATCH 24/45] move county user input to while loop --- poverty/src/poverty/Program.java | 54 +++++++++++++++++--------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 26f35f2..fab9b00 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -23,33 +23,37 @@ public static void main(String[] args) { } } - try { - Scanner scanFile = new Scanner(file); - // capture user input for county - System.out.print("Enter a county in " + state + ": "); - String county = scanInput.nextLine(); - // find and print the line matching the county entered by user - String line; - boolean countyFound = false; - while (scanFile.hasNextLine()) { - line = scanFile.nextLine(); + boolean countyFound = false; + while (!countyFound) { + try { + Scanner scanFile = new Scanner(file); + // capture user input for county + System.out.print("Enter a county in " + state + ": "); + String county = scanInput.nextLine(); + // find and print the line matching the county entered by user + String line; - if(line.toLowerCase().contains(county.toLowerCase())) { - County userCounty = new County(line); - System.out.println("County: " + userCounty.name ); - System.out.println("Percentage of children in poverty: " + userCounty.povPercent); - System.out.println("Number of children in poverty: " + userCounty.povCount); - System.out.println("Median household income: "+ userCounty.medIncome); - countyFound = true; - } - } - scanFile.close(); - if(!countyFound) { - System.out.println("Invalid county for " + state); - } - } catch (FileNotFoundException e) { - e.printStackTrace(); + while (scanFile.hasNextLine()) { + line = scanFile.nextLine(); + + if(line.toLowerCase().contains(county.toLowerCase())) { + County userCounty = new County(line); + System.out.println("County: " + userCounty.name ); + System.out.println("Percentage of children in poverty: " + userCounty.povPercent); + System.out.println("Number of children in poverty: " + userCounty.povCount); + System.out.println("Median household income: "+ userCounty.medIncome); + countyFound = true; + } + } + scanFile.close(); + if(!countyFound) { + System.out.println("Invalid county for " + state); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } } + scanInput.close(); } } From 269c726db01d57a61c4a0c015744ade698f13307 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:17:37 -0700 Subject: [PATCH 25/45] remove if statement for county not found --- poverty/src/poverty/Program.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index fab9b00..a92ef0d 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -46,9 +46,6 @@ public static void main(String[] args) { } } scanFile.close(); - if(!countyFound) { - System.out.println("Invalid county for " + state); - } } catch (FileNotFoundException e) { e.printStackTrace(); } From 858f997ca322d07e1823435609f60682ad31aef2 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:38:09 -0700 Subject: [PATCH 26/45] end program if q is entered for state input --- poverty/src/poverty/Program.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index a92ef0d..2b790cb 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -13,13 +13,17 @@ public static void main(String[] args) { String state = null; while(file == null) { // capture user input for state - System.out.print("Enter 'CA' for California or 'WA' for Washington: "); + System.out.print("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: "); state = scanInput.nextLine().toUpperCase(); // use appropriate file based on user state selection if(state.equals("WA")) { file = new File("washington.txt"); } else if(state.equals("CA")){ file = new File("california.txt"); + } else if(state.equals("Q")) { + scanInput.close(); + System.out.println("BYE."); + return; } } From a4974294fa014ead4aa357744dfa6b55041edc71 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 10:41:45 -0700 Subject: [PATCH 27/45] allow user to exit during county input loop --- poverty/src/poverty/Program.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 2b790cb..6b4e4b3 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -32,8 +32,13 @@ public static void main(String[] args) { try { Scanner scanFile = new Scanner(file); // capture user input for county - System.out.print("Enter a county in " + state + ": "); + System.out.print("Enter a county in " + state + " or 'q' to quit: "); String county = scanInput.nextLine(); + if (county.equals("q")) { + scanFile.close(); + System.out.println("BYE."); + return; + } // find and print the line matching the county entered by user String line; From c5fe4a7fe87317af2009e08b24c00b67ac0add75 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 11:54:39 -0700 Subject: [PATCH 28/45] create method to find extreme pov percents for a given state's file, method currently works for finding highest percent --- poverty/src/poverty/Program.java | 47 ++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 6b4e4b3..3161fe4 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -5,8 +5,23 @@ import java.util.Scanner; public class Program { - public static void main(String[] args) { + public static void main(String[] args) throws FileNotFoundException { System.out.println("Welcome to the CA/WA Poverty Educator!"); + + File caFile = new File("california.txt"); + File waFile = new File("washington.txt"); + + + County highestCACounty = findExtremeCounty(caFile, true); +// County lowestCACounty = findExtremeCounty(caFile, false); +// County highestWACounty = findExtremeCounty(waFile, true); +// County lowestWACounty = findExtremeCounty(waFile, false); +// + System.out.print("In California, the county with the highest poverty percent is: "); + System.out.println(highestCACounty.name); + System.out.println(highestCACounty.povPercent); + + Scanner scanInput = new Scanner(System.in); File file = null; @@ -17,9 +32,9 @@ public static void main(String[] args) { state = scanInput.nextLine().toUpperCase(); // use appropriate file based on user state selection if(state.equals("WA")) { - file = new File("washington.txt"); + file = waFile; } else if(state.equals("CA")){ - file = new File("california.txt"); + file = caFile; } else if(state.equals("Q")) { scanInput.close(); System.out.println("BYE."); @@ -62,4 +77,30 @@ public static void main(String[] args) { scanInput.close(); } + + + public static County findExtremeCounty(File file, boolean highest) throws FileNotFoundException { + + Scanner scanFile = new Scanner(file); + String currentLine = scanFile.nextLine(); + String[] currentLineColumns; + Double currentLinePovPercent; + String targetLine = currentLine; + String[] targetLineColumns = targetLine.split("\\s+"); + Double targetPovPercent = Double.parseDouble(targetLineColumns[11]); + + + while (scanFile.hasNextLine()) { + currentLine = scanFile.nextLine(); + currentLineColumns = currentLine.split("\\s+"); + currentLinePovPercent = Double.parseDouble(currentLineColumns[11]); + + if (currentLinePovPercent > targetPovPercent) { + targetLine = currentLine; + targetPovPercent = currentLinePovPercent; + } + } + scanFile.close(); + return new County(targetLine); + } } From d49a95b4a29d88306b8f7a81e525ffd25ce2debb Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 12:17:36 -0700 Subject: [PATCH 29/45] extreme county finder method works for finding county with lowest percentage too --- poverty/src/poverty/Program.java | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 3161fe4..bef5967 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -13,14 +13,23 @@ public static void main(String[] args) throws FileNotFoundException { County highestCACounty = findExtremeCounty(caFile, true); -// County lowestCACounty = findExtremeCounty(caFile, false); -// County highestWACounty = findExtremeCounty(waFile, true); -// County lowestWACounty = findExtremeCounty(waFile, false); -// + County lowestCACounty = findExtremeCounty(caFile, false); + County highestWACounty = findExtremeCounty(waFile, true); + County lowestWACounty = findExtremeCounty(waFile, false); + System.out.print("In California, the county with the highest poverty percent is: "); System.out.println(highestCACounty.name); System.out.println(highestCACounty.povPercent); + System.out.print("And the county with the lowest poverty percent is: "); + System.out.println(lowestCACounty.name); + System.out.println(lowestCACounty.povPercent); + System.out.print("In Washington, the county with the highest poverty percent is: "); + System.out.println(highestWACounty.name); + System.out.println(highestWACounty.povPercent); + System.out.print("And the county with the lowest poverty percent is: "); + System.out.println(lowestWACounty.name); + System.out.println(lowestWACounty.povPercent); Scanner scanInput = new Scanner(System.in); @@ -95,9 +104,16 @@ public static County findExtremeCounty(File file, boolean highest) throws FileNo currentLineColumns = currentLine.split("\\s+"); currentLinePovPercent = Double.parseDouble(currentLineColumns[11]); - if (currentLinePovPercent > targetPovPercent) { - targetLine = currentLine; - targetPovPercent = currentLinePovPercent; + if (highest) { + if (currentLinePovPercent > targetPovPercent) { + targetLine = currentLine; + targetPovPercent = currentLinePovPercent; + } + } else { + if (currentLinePovPercent < targetPovPercent) { + targetLine = currentLine; + targetPovPercent = currentLinePovPercent; + } } } scanFile.close(); From 8a113230f277a2a3bf1fc1cf7795361cd6bca1a6 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 14:02:08 -0700 Subject: [PATCH 30/45] print all required info --- poverty/src/poverty/Program.java | 47 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index bef5967..1f77104 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -7,39 +7,54 @@ public class Program { public static void main(String[] args) throws FileNotFoundException { System.out.println("Welcome to the CA/WA Poverty Educator!"); - + System.out.println(); + File caFile = new File("california.txt"); File waFile = new File("washington.txt"); - County highestCACounty = findExtremeCounty(caFile, true); County lowestCACounty = findExtremeCounty(caFile, false); County highestWACounty = findExtremeCounty(waFile, true); County lowestWACounty = findExtremeCounty(waFile, false); - System.out.print("In California, the county with the highest poverty percent is: "); + System.out.println("************"); + System.out.println("*CALIFORNIA*"); + System.out.println("************"); + System.out.print("County with highest % poverty: "); System.out.println(highestCACounty.name); - System.out.println(highestCACounty.povPercent); - System.out.print("And the county with the lowest poverty percent is: "); + System.out.println("Percentage of children in poverty: " + highestCACounty.povPercent); + System.out.println("Number of children in poverty: " + highestCACounty.povCount); + System.out.println("Median household income: "+ highestCACounty.medIncome); + System.out.println("------------"); + System.out.print("County with lowest % poverty: "); System.out.println(lowestCACounty.name); - System.out.println(lowestCACounty.povPercent); - - System.out.print("In Washington, the county with the highest poverty percent is: "); + System.out.println("Percentage of children in poverty: " + lowestCACounty.povPercent); + System.out.println("Number of children in poverty: " + lowestCACounty.povCount); + System.out.println("Median household income: "+ lowestCACounty.medIncome); + System.out.println("************"); + System.out.println("*WASHINGTON*"); + System.out.println("************"); + System.out.print("County with highest % poverty: "); System.out.println(highestWACounty.name); - System.out.println(highestWACounty.povPercent); - System.out.print("And the county with the lowest poverty percent is: "); + System.out.println("Percentage of children in poverty: " + highestWACounty.povPercent); + System.out.println("Number of children in poverty: " + highestWACounty.povCount); + System.out.println("Median household income: "+ highestWACounty.medIncome); + System.out.println("------------"); + System.out.print("County with lowest % poverty: "); System.out.println(lowestWACounty.name); - System.out.println(lowestWACounty.povPercent); - + System.out.println("Percentage of children in poverty: " + lowestWACounty.povPercent); + System.out.println("Number of children in poverty: " + lowestWACounty.povCount); + System.out.println("Median household income: "+ lowestWACounty.medIncome); + System.out.println("***************************************************************"); + System.out.println(); Scanner scanInput = new Scanner(System.in); File file = null; String state = null; while(file == null) { - // capture user input for state System.out.print("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: "); + System.out.println(); state = scanInput.nextLine().toUpperCase(); - // use appropriate file based on user state selection if(state.equals("WA")) { file = waFile; } else if(state.equals("CA")){ @@ -55,15 +70,15 @@ public static void main(String[] args) throws FileNotFoundException { while (!countyFound) { try { Scanner scanFile = new Scanner(file); - // capture user input for county System.out.print("Enter a county in " + state + " or 'q' to quit: "); + System.out.println(); String county = scanInput.nextLine(); if (county.equals("q")) { scanFile.close(); System.out.println("BYE."); return; } - // find and print the line matching the county entered by user + String line; while (scanFile.hasNextLine()) { From fc72fb007270506cd60a2011797546ac640de6d1 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 14:29:01 -0700 Subject: [PATCH 31/45] create python files --- poverty/county.py | 0 poverty/program.py | 1 + 2 files changed, 1 insertion(+) create mode 100644 poverty/county.py create mode 100644 poverty/program.py diff --git a/poverty/county.py b/poverty/county.py new file mode 100644 index 0000000..e69de29 diff --git a/poverty/program.py b/poverty/program.py new file mode 100644 index 0000000..39fb7b0 --- /dev/null +++ b/poverty/program.py @@ -0,0 +1 @@ +print "Welcome to the CA/WA Poverty Educator!" From 564d7fb102a1c7704039d5b821efd82a07b7091c Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 14:37:41 -0700 Subject: [PATCH 32/45] open and close two files --- poverty/program.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/poverty/program.py b/poverty/program.py index 39fb7b0..926ba09 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -1 +1,8 @@ print "Welcome to the CA/WA Poverty Educator!" +print "" +ca_file = open("california.txt") +wa_file = open("washington.txt") + +ca_file.close() +wa_file.close() +# file.close() From 4f300a2b9ec3f408a117553964226b0de9e529a3 Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 15:17:19 -0700 Subject: [PATCH 33/45] create find_extreme_county method --- poverty/program.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/poverty/program.py b/poverty/program.py index 926ba09..a8ebff9 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -3,6 +3,27 @@ ca_file = open("california.txt") wa_file = open("washington.txt") +def find_extreme_county(file): + # current_line = file.readline() + target_line = file.readline() + target_pov_percent = float(target_line.split()[11]) + + for line in file: + line_pov_percent = float(line.split()[11]) + if (line_pov_percent > target_pov_percent): + target_line = line + target_pov_percent = line_pov_percent + + return target_line + +# highest_ca_county = find_extreme_county(ca_file, true); +# lowest_ca_county = find_extreme_county(wa_file, false); +# highest_wa_county = find_extreme_county(ca_file, true); +# lowest_wa_county = find_extreme_county(wa_file, false); +# + +# find_extreme_county(ca_file) + ca_file.close() wa_file.close() # file.close() From 9d54ecf32359d5186a5f6888366b3ec29b01c0ff Mon Sep 17 00:00:00 2001 From: Kelly Date: Thu, 7 Apr 2016 15:41:07 -0700 Subject: [PATCH 34/45] import County class in program file, return county with highest pov percent in find_extreme_county method, County objects now have a name attribute --- poverty/county.py | 5 +++++ poverty/county.pyc | Bin 0 -> 633 bytes poverty/program.py | 8 +++++--- 3 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 poverty/county.pyc diff --git a/poverty/county.py b/poverty/county.py index e69de29..e32b869 100644 --- a/poverty/county.py +++ b/poverty/county.py @@ -0,0 +1,5 @@ +class County: + NAME_START = 193 + NAME_END = 238 + def __init__(self, line): + self.name = line[County.NAME_START:County.NAME_END] diff --git a/poverty/county.pyc b/poverty/county.pyc new file mode 100644 index 0000000000000000000000000000000000000000..2494812f7760dfd87651a3295fd819b74a5aa212 GIT binary patch literal 633 zcmcJL!A^rf5QYb+#5D12V&cIYC-()6THBsf4p3v{vLWr-VCh2G#e}36qc7&8_yWE7 z0{*j9eE|jLXJ;1X`)7mCgW=0Zct5Az72th|Fo%!@o`4n}y%D_u9t1TR7TX*vubQ7=I$U)>&~I2EOcR|WU^r@ zdC?wpx5;Ltbe^SLSBthpn(#;of1L2i{<``zYwo0&Vi*v5e8)Y Date: Thu, 7 Apr 2016 15:54:15 -0700 Subject: [PATCH 35/45] all required attributes for county exist and print for highest of each state --- poverty/county.py | 4 ++++ poverty/county.pyc | Bin 633 -> 774 bytes poverty/program.py | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/poverty/county.py b/poverty/county.py index e32b869..59cbb0e 100644 --- a/poverty/county.py +++ b/poverty/county.py @@ -3,3 +3,7 @@ class County: NAME_END = 238 def __init__(self, line): self.name = line[County.NAME_START:County.NAME_END] + details = line.split() + self.pov_percent = details[11] + self.pov_count = details[8] + self.med_income = details[20] diff --git a/poverty/county.pyc b/poverty/county.pyc index 2494812f7760dfd87651a3295fd819b74a5aa212..7f6aa232ad1c99f15ad6b988cc6096f86120d1c5 100644 GIT binary patch delta 286 zcmXYry-veG5QJyXjuRZ*Atb6OqH)7hP?G{A3YrtL59K1qw(vsbC&-R@B^ywFCxMgB#3Szy?}fh4=tA2CYF( zxYCDF4`zULM+vEF9OH=@9QTXNo?xEGizgAz1!NoX0BvD z`{%5B6N-h_F1NnSs?aHe)6R1_ovzb_U{NDIih9$WX$-kOd)`7!+$57~+{3QWzM5 zH5h@?ei|&385woOH9#6mSU|c`bJD Date: Fri, 8 Apr 2016 09:36:19 -0700 Subject: [PATCH 36/45] add if else statement for finding highest or lowest poverty in each state --- poverty/county.pyc | Bin 774 -> 774 bytes poverty/program.py | 21 +++++++----- poverty/src/poverty/Program.java | 54 +++++++++++++++---------------- 3 files changed, 40 insertions(+), 35 deletions(-) diff --git a/poverty/county.pyc b/poverty/county.pyc index 7f6aa232ad1c99f15ad6b988cc6096f86120d1c5..c710f5202161abfb45774f59b6acce48481cf279 100644 GIT binary patch delta 16 XcmZo;Yhz<){>;m@^CtU7_Ww)(Dn$i< delta 16 XcmZo;Yhz<){>;nu^by-e_Ww)(E2;&v diff --git a/poverty/program.py b/poverty/program.py index 73f56a4..76ddb67 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -5,22 +5,27 @@ ca_file = open("california.txt") wa_file = open("washington.txt") -def find_extreme_county(file): +def find_extreme_county(file, highest): target_line = file.readline() target_pov_percent = float(target_line.split()[11]) for line in file: line_pov_percent = float(line.split()[11]) - if (line_pov_percent > target_pov_percent): - target_line = line - target_pov_percent = line_pov_percent + if (highest): + if (line_pov_percent > target_pov_percent): + target_line = line + target_pov_percent = line_pov_percent + else: + if (line_pov_percent < target_pov_percent): + target_line = line + target_pov_percent = line_pov_percent return County(target_line) -highest_ca_county = find_extreme_county(ca_file) -# lowest_ca_county = find_extreme_county(ca_file, false) -highest_wa_county = find_extreme_county(wa_file); -# lowest_wa_county = find_extreme_county(wa_file, false) +highest_ca_county = find_extreme_county(ca_file, True) +# lowest_ca_county = find_extreme_county(ca_file, False) +highest_wa_county = find_extreme_county(wa_file, True); +# lowest_wa_county = find_extreme_county(wa_file, False) print "************" diff --git a/poverty/src/poverty/Program.java b/poverty/src/poverty/Program.java index 1f77104..e881270 100644 --- a/poverty/src/poverty/Program.java +++ b/poverty/src/poverty/Program.java @@ -5,10 +5,10 @@ import java.util.Scanner; public class Program { - public static void main(String[] args) throws FileNotFoundException { + public static void main(String[] args) throws FileNotFoundException { System.out.println("Welcome to the CA/WA Poverty Educator!"); System.out.println(); - + File caFile = new File("california.txt"); File waFile = new File("washington.txt"); @@ -17,8 +17,8 @@ public static void main(String[] args) throws FileNotFoundException { County highestWACounty = findExtremeCounty(waFile, true); County lowestWACounty = findExtremeCounty(waFile, false); - System.out.println("************"); - System.out.println("*CALIFORNIA*"); + System.out.println("************"); + System.out.println("*CALIFORNIA*"); System.out.println("************"); System.out.print("County with highest % poverty: "); System.out.println(highestCACounty.name); @@ -31,8 +31,8 @@ public static void main(String[] args) throws FileNotFoundException { System.out.println("Percentage of children in poverty: " + lowestCACounty.povPercent); System.out.println("Number of children in poverty: " + lowestCACounty.povCount); System.out.println("Median household income: "+ lowestCACounty.medIncome); - System.out.println("************"); - System.out.println("*WASHINGTON*"); + System.out.println("************"); + System.out.println("*WASHINGTON*"); System.out.println("************"); System.out.print("County with highest % poverty: "); System.out.println(highestWACounty.name); @@ -49,7 +49,7 @@ public static void main(String[] args) throws FileNotFoundException { System.out.println(); Scanner scanInput = new Scanner(System.in); - File file = null; + File file = null; String state = null; while(file == null) { System.out.print("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: "); @@ -65,7 +65,7 @@ public static void main(String[] args) throws FileNotFoundException { return; } } - + boolean countyFound = false; while (!countyFound) { try { @@ -73,18 +73,18 @@ public static void main(String[] args) throws FileNotFoundException { System.out.print("Enter a county in " + state + " or 'q' to quit: "); System.out.println(); String county = scanInput.nextLine(); - if (county.equals("q")) { + if (county.equals("q")) { scanFile.close(); System.out.println("BYE."); - return; + return; } - - String line; - + + String line; + while (scanFile.hasNextLine()) { line = scanFile.nextLine(); - - if(line.toLowerCase().contains(county.toLowerCase())) { + + if(line.toLowerCase().contains(county.toLowerCase())) { County userCounty = new County(line); System.out.println("County: " + userCounty.name ); System.out.println("Percentage of children in poverty: " + userCounty.povPercent); @@ -96,29 +96,29 @@ public static void main(String[] args) throws FileNotFoundException { scanFile.close(); } catch (FileNotFoundException e) { e.printStackTrace(); - } + } } - - scanInput.close(); + + scanInput.close(); } - - + + public static County findExtremeCounty(File file, boolean highest) throws FileNotFoundException { - + Scanner scanFile = new Scanner(file); - String currentLine = scanFile.nextLine(); - String[] currentLineColumns; - Double currentLinePovPercent; + String currentLine = scanFile.nextLine(); + String[] currentLineColumns; + Double currentLinePovPercent; String targetLine = currentLine; String[] targetLineColumns = targetLine.split("\\s+"); Double targetPovPercent = Double.parseDouble(targetLineColumns[11]); - - + + while (scanFile.hasNextLine()) { currentLine = scanFile.nextLine(); currentLineColumns = currentLine.split("\\s+"); currentLinePovPercent = Double.parseDouble(currentLineColumns[11]); - + if (highest) { if (currentLinePovPercent > targetPovPercent) { targetLine = currentLine; From 3f01809aa2bd43286fcef05dcc81f9a78417979d Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 09:43:42 -0700 Subject: [PATCH 37/45] print details of highest and lowest poverty counties for each state --- poverty/program.py | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/poverty/program.py b/poverty/program.py index 76ddb67..d5acbce 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -2,10 +2,12 @@ print "Welcome to the CA/WA Poverty Educator!" print "" -ca_file = open("california.txt") -wa_file = open("washington.txt") +ca_file_name = "california.txt" +wa_file_name = "washington.txt" + +def find_extreme_county(file_name, highest): + file = open(file_name) -def find_extreme_county(file, highest): target_line = file.readline() target_pov_percent = float(target_line.split()[11]) @@ -19,14 +21,13 @@ def find_extreme_county(file, highest): if (line_pov_percent < target_pov_percent): target_line = line target_pov_percent = line_pov_percent - + file.close() return County(target_line) -highest_ca_county = find_extreme_county(ca_file, True) -# lowest_ca_county = find_extreme_county(ca_file, False) -highest_wa_county = find_extreme_county(wa_file, True); -# lowest_wa_county = find_extreme_county(wa_file, False) - +highest_ca_county = find_extreme_county(ca_file_name, True) +lowest_ca_county = find_extreme_county(ca_file_name, False) +highest_wa_county = find_extreme_county(wa_file_name, True); +lowest_wa_county = find_extreme_county(wa_file_name, False) print "************" print "*CALIFORNIA*" @@ -36,10 +37,10 @@ def find_extreme_county(file, highest): print "Number of children in poverty: " + highest_ca_county.pov_count print "Median household income: " + highest_ca_county.med_income print "------------" -# print "County with lowest percent poverty: " + lowest_ca_county.name -# print "Percentage of children in poverty: " + lowest_ca_county.pov_percent -# print "Number of children in poverty: " + lowest_ca_county.pov_count -# print "Median household income: " + lowest_ca_county.med_income +print "County with lowest percent poverty: " + lowest_ca_county.name +print "Percentage of children in poverty: " + lowest_ca_county.pov_percent +print "Number of children in poverty: " + lowest_ca_county.pov_count +print "Median household income: " + lowest_ca_county.med_income print "************" print "*WASHINGTON*" print "************" @@ -48,14 +49,9 @@ def find_extreme_county(file, highest): print "Number of children in poverty: " + highest_wa_county.pov_count print "Median household income: " + highest_wa_county.med_income print "------------" -# print "County with lowest percent poverty: " + lowest_wa_county.name -# print "Percentage of children in poverty: " + lowest_wa_county.pov_percent -# print "Number of children in poverty: " + lowest_wa_county.pov_count -# print "Median household income: " + lowest_wa_county.med_income +print "County with lowest percent poverty: " + lowest_wa_county.name +print "Percentage of children in poverty: " + lowest_wa_county.pov_percent +print "Number of children in poverty: " + lowest_wa_county.pov_count +print "Median household income: " + lowest_wa_county.med_income print "***************************************************************" print "" - - -ca_file.close() -wa_file.close() -# file.close() From 12d00da570bf5ade51d7926e6da441f603b6aef3 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 09:56:15 -0700 Subject: [PATCH 38/45] capture user input for state --- poverty/program.py | 1 + 1 file changed, 1 insertion(+) diff --git a/poverty/program.py b/poverty/program.py index d5acbce..cb0ba9c 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -55,3 +55,4 @@ def find_extreme_county(file_name, highest): print "Median household income: " + lowest_wa_county.med_income print "***************************************************************" print "" +state = raw_input("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: ").upper() From 1d52abfed10fa5b669eb8fc06687b6f944a4e971 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:04:27 -0700 Subject: [PATCH 39/45] if else statement for setting file name or quitting program --- poverty/program.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/poverty/program.py b/poverty/program.py index cb0ba9c..71b391c 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -56,3 +56,10 @@ def find_extreme_county(file_name, highest): print "***************************************************************" print "" state = raw_input("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: ").upper() +if (state == "WA"): + wa_file_name = "washington.txt" +elif (state == "CA"): + ca_file_name = "california.txt" +elif (state == "Q"): + print "BYE." + quit() From 1cf4d0928394c09e557c54fc953bbef05382c293 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:07:23 -0700 Subject: [PATCH 40/45] capture user input for county --- poverty/program.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/poverty/program.py b/poverty/program.py index 71b391c..292a0fa 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -63,3 +63,5 @@ def find_extreme_county(file_name, highest): elif (state == "Q"): print "BYE." quit() + +county = raw_input("Enter a county in " + state + " or 'q' to quit: ") From 4b6be080bb48154c254aaad641f0b4fe66054369 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:33:27 -0700 Subject: [PATCH 41/45] create print_county method for printing matching counties and determining if any counties were found --- poverty/program.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/poverty/program.py b/poverty/program.py index 292a0fa..4401176 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -24,6 +24,20 @@ def find_extreme_county(file_name, highest): file.close() return County(target_line) +def print_county(file_name, user_county): + file = open(file_name) + county_found = False + for line in file: + if (user_county in line.lower()): + county = County(line) + county_found = True + print "County: " + county.name + print "Percentage of children in poverty: " + county.pov_percent + print "Number of children in poverty: " + county.pov_count + print "Median household income: " + county.med_income + file.close() + return county_found + highest_ca_county = find_extreme_county(ca_file_name, True) lowest_ca_county = find_extreme_county(ca_file_name, False) highest_wa_county = find_extreme_county(wa_file_name, True); @@ -57,11 +71,16 @@ def find_extreme_county(file_name, highest): print "" state = raw_input("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: ").upper() if (state == "WA"): - wa_file_name = "washington.txt" + file_name = "washington.txt" elif (state == "CA"): - ca_file_name = "california.txt" + file_name = "california.txt" elif (state == "Q"): print "BYE." quit() -county = raw_input("Enter a county in " + state + " or 'q' to quit: ") +user_county = raw_input("Enter a county in " + state + " or 'q' to quit: ").lower() +if (user_county == "q"): + print "BYE." + quit() + +success = print_county(file_name, user_county) From 323bb7f2346a4d38ed46c06274b4c756e5115eec Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:39:33 -0700 Subject: [PATCH 42/45] prompt user for county until county is found or user types q --- poverty/program.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/poverty/program.py b/poverty/program.py index 4401176..b2533f8 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -24,19 +24,23 @@ def find_extreme_county(file_name, highest): file.close() return County(target_line) -def print_county(file_name, user_county): - file = open(file_name) +def print_county(file_name): county_found = False - for line in file: - if (user_county in line.lower()): - county = County(line) - county_found = True - print "County: " + county.name - print "Percentage of children in poverty: " + county.pov_percent - print "Number of children in poverty: " + county.pov_count - print "Median household income: " + county.med_income - file.close() - return county_found + while (not county_found): + user_county = raw_input("Enter a county in " + state + " or 'q' to quit: ").lower() + if (user_county == "q"): + print "BYE." + quit() + file = open(file_name) + for line in file: + if (user_county in line.lower()): + county = County(line) + county_found = True + print "County: " + county.name + print "Percentage of children in poverty: " + county.pov_percent + print "Number of children in poverty: " + county.pov_count + print "Median household income: " + county.med_income + file.close() highest_ca_county = find_extreme_county(ca_file_name, True) lowest_ca_county = find_extreme_county(ca_file_name, False) @@ -78,9 +82,4 @@ def print_county(file_name, user_county): print "BYE." quit() -user_county = raw_input("Enter a county in " + state + " or 'q' to quit: ").lower() -if (user_county == "q"): - print "BYE." - quit() - -success = print_county(file_name, user_county) +print_county(file_name) From 6501cec0068ee9aa218846bdaa562b04232fbdc4 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:43:04 -0700 Subject: [PATCH 43/45] program re-prompts user for state until wa, ca, or q is entered --- poverty/program.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/poverty/program.py b/poverty/program.py index b2533f8..e47a133 100644 --- a/poverty/program.py +++ b/poverty/program.py @@ -73,13 +73,15 @@ def print_county(file_name): print "Median household income: " + lowest_wa_county.med_income print "***************************************************************" print "" -state = raw_input("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: ").upper() -if (state == "WA"): - file_name = "washington.txt" -elif (state == "CA"): - file_name = "california.txt" -elif (state == "Q"): - print "BYE." - quit() +file_name = None +while (file_name is None): + state = raw_input("Enter 'CA' for California, 'WA' for Washington, or 'q' to quit: ").upper() + if (state == "WA"): + file_name = "washington.txt" + elif (state == "CA"): + file_name = "california.txt" + elif (state == "Q"): + print "BYE." + quit() print_county(file_name) From 5de7f525875b25f6c1d66443ec66b76dc2705ad1 Mon Sep 17 00:00:00 2001 From: Kelly Date: Fri, 8 Apr 2016 10:50:55 -0700 Subject: [PATCH 44/45] remove county.pyc from git --- poverty/county.pyc | Bin 774 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 poverty/county.pyc diff --git a/poverty/county.pyc b/poverty/county.pyc deleted file mode 100644 index c710f5202161abfb45774f59b6acce48481cf279..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 774 zcmcIiJ5Iwu5FOk3Kp-6gQBcsi!WTe5NK!#kI6(+EtH@rWO&r_uPLM2x3NA&-F}MT` z7hq-_!3DtUd7jy|-+Qxb@2lH+`)J?Cu)REbUQyU1f`o1l5(i!ZUH~2`%M=k2xl9x_Ae{KDW8N7)31XLkr#Si)c0{mo009;? zx^TJyP#(`N8f@p;g^f@j^FmV!7o=!O;nhW(P1L5xW{-Hy4#NR~&sj(T*dZAAMng53 z_QEOhf|SGY0J-06w$j+7#1^SRWS$~_QiU#KogwaS>zH>$$W}U0CX4fxmS%;->hw{P z)MOgl^i861W>V`@3Ig_$vf$3@(grs=O{*nAFwl01c@dZlb(s~VE`r-xHeb)?+6Lr9 zmska&U7Zz`xL2fZP$@QVxjS$UoqeZE!{FL7T=iDRW!d9qHa4EZEOK9rCf{dM Date: Fri, 8 Apr 2016 10:53:19 -0700 Subject: [PATCH 45/45] update .gitignore to include pyc files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3c8c53c..8fdb495 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,6 @@ local.properties # Code Recommenders .recommenders/ + +# Python pyc files +*.pyc