Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.*;
  3.  
  4. public class assignment6b {
  5. public static void main(String[] args) throws IOException {
  6. //-------------------------
  7. int i=0; //makes i an int and 0
  8. int n=0; //makes n an int and 0
  9. int voters[]=new int[10]; //creates an array called voters with 10 int elements to store both bronx and brooklyn voters
  10. int zipcodes[]=new int[10]; // creates an array called zipcodes with 10 int elements to store both bronx and brooklyn zipcodes
  11. int bklnzip[]=new int[1000]; //creates an array called bklnzip with 1000 int elements to store brooklyn zipcodes
  12. int bklnvote[]=new int[1000]; //creates an array called bklnvote with 1000 int elements to store brooklyn voters
  13. int bxzip[]=new int[1000]; // creates an array called bxzip with 1000 int elements to store bronx zipcodes
  14. int bxvote[]=new int[1000]; // creates an array called bxvote with 1000 int elements to store bronx vote
  15. Scanner x=new Scanner(new File("information.txt")); // creates a scanner called x that reads the file "information.txt"
  16. while (x.hasNext()){ //while loop. If x has any more values do a loop
  17. zipcodes[i]=x.nextInt(); //reads both bronx and brooklyn zipcodes
  18. voters[i]=x.nextInt(); //reads both bronx and brooklyn voters
  19. if (zipcodes[i]>11199 && zipcodes[i]<11300){
  20. bklnzip[n]=zipcodes[i];
  21. bklnvote[n]=voters[i];
  22. System.out.println("Brooklyn Zipcode: "+bklnzip[n] + " Brooklyn Voters: " +bklnvote[n]);
  23. n++;
  24. }
  25. else{
  26. bxzip[n]=zipcodes[i];
  27. bxvote[n]=voters[i];
  28. System.out.println("Bronx Zipcode: "+bxzip[n] + " Bronx Voters: " + bxvote[n]);
  29.  
  30. }
  31. i++;
  32. }
  33. dataPrint(zipcodes,voters); //Question: Why does zipcodes and voters not need the [i] next to it?
  34. for (int y=0;y<10; y++){
  35. if(isBrooklyn(zipcodes)==true){
  36. System.out.println(zipcodes[y]+ " is in Brooklyn");
  37. }
  38. else if (isBrooklyn(zipcodes)==false){
  39. System.out.println(zipcodes[y]+" is in Bronx");
  40. }
  41.  
  42. }
  43. }
  44. public static void dataPrint(int [] zip, int [] vote){
  45. for (int i=0;i<10; i++){
  46. System.out.println("Zipcodes: " + zip[i] + " Voters: " + vote[i]);
  47. }
  48. }
  49. public static boolean isBrooklyn(int [] zip1){
  50. for (int i=0;i<10; i++){
  51. if (zip1[i]>11199 && zip1[i]<11300){
  52. System.out.println("hi");
  53. return true;
  54. }
  55.  
  56. }
  57. return false;
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement