Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- public class makeUp1 {
- public static void main(String[] args)throws FileNotFoundException {
- Scanner console = new Scanner(System.in);
- System.out.print("What is the file name?");
- String fileName = console.next();
- Scanner input = new Scanner (new File(fileName));
- String [] name = new String [50];
- String [] city = new String [50];
- int [] numPeople = new int [50];
- String [] nameList = new String [50];
- int index = 0;
- while (input.hasNext()) {
- name[index] = input.next();
- city[index] = input.next();
- index++;
- }
- for(int i = 0 ; i<index;i++) {
- if(city[i].equals("Seattle")) {
- numPeople[0]+= 1;
- nameList[0]+= name[i]+"\n";
- }
- else if(city[i].equals("Yakima")) {
- numPeople[1]+= 1;
- nameList[1]+= name[i]+"\n";
- }
- else if(city[i].equals("LaPush")) {
- numPeople[2]+= 1;
- nameList[2]+= name[i]+"\n";
- }
- else if(city[i].equals("Everett")) {
- numPeople[3]+= 1;
- nameList[3]+= name[i]+"\n";
- }
- }
- System.out.println(city[0] + " students: "+numPeople[0]);
- System.out.println(nameList[0]);
- System.out.println(city[1] + " students: "+numPeople[1]);
- System.out.println(nameList[1]);
- System.out.println(city[2] + " students: "+numPeople[2]);
- System.out.println(nameList[2]);
- System.out.println(city[3] + " students: "+numPeople[3]);
- System.out.println(nameList[3]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement