Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.*;
- public class assignment6b {
- public static void main(String[] args) throws IOException {
- //-------------------------
- int i=0; //makes i an int and 0
- int n=0; //makes n an int and 0
- int voters[]=new int[10]; //creates an array called voters with 10 int elements to store both bronx and brooklyn voters
- int zipcodes[]=new int[10]; // creates an array called zipcodes with 10 int elements to store both bronx and brooklyn zipcodes
- int bklnzip[]=new int[1000]; //creates an array called bklnzip with 1000 int elements to store brooklyn zipcodes
- int bklnvote[]=new int[1000]; //creates an array called bklnvote with 1000 int elements to store brooklyn voters
- int bxzip[]=new int[1000]; // creates an array called bxzip with 1000 int elements to store bronx zipcodes
- int bxvote[]=new int[1000]; // creates an array called bxvote with 1000 int elements to store bronx vote
- Scanner x=new Scanner(new File("information.txt")); // creates a scanner called x that reads the file "information.txt"
- while (x.hasNext()){ //while loop. If x has any more values do a loop
- zipcodes[i]=x.nextInt(); //reads both bronx and brooklyn zipcodes
- voters[i]=x.nextInt(); //reads both bronx and brooklyn voters
- if (zipcodes[i]>11199 && zipcodes[i]<11300){
- bklnzip[n]=zipcodes[i];
- bklnvote[n]=voters[i];
- System.out.println("Brooklyn Zipcode: "+bklnzip[n] + " Brooklyn Voters: " +bklnvote[n]);
- n++;
- }
- else{
- bxzip[n]=zipcodes[i];
- bxvote[n]=voters[i];
- System.out.println("Bronx Zipcode: "+bxzip[n] + " Bronx Voters: " + bxvote[n]);
- }
- i++;
- }
- dataPrint(zipcodes,voters); //Question: Why does zipcodes and voters not need the [i] next to it?
- for (int y=0;y<10; y++){
- if(isBrooklyn(zipcodes)==true){
- System.out.println(zipcodes[y]+ " is in Brooklyn");
- }
- else if (isBrooklyn(zipcodes)==false){
- System.out.println(zipcodes[y]+" is in Bronx");
- }
- }
- }
- public static void dataPrint(int [] zip, int [] vote){
- for (int i=0;i<10; i++){
- System.out.println("Zipcodes: " + zip[i] + " Voters: " + vote[i]);
- }
- }
- public static boolean isBrooklyn(int [] zip1){
- for (int i=0;i<10; i++){
- if (zip1[i]>11199 && zip1[i]<11300){
- System.out.println("hi");
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement