Advertisement
Guest User

Untitled

a guest
Feb 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4.  
  5.  
  6. public class makeUp1 {
  7.  
  8. public static void main(String[] args)throws FileNotFoundException {
  9. Scanner console = new Scanner(System.in);
  10. System.out.print("What is the file name?");
  11. String fileName = console.next();
  12. Scanner input = new Scanner (new File(fileName));
  13.  
  14. String [] name = new String [50];
  15. String [] city = new String [50];
  16. int [] numPeople = new int [50];
  17. String [] nameList = new String [50];
  18. int index = 0;
  19. while (input.hasNext()) {
  20.  
  21. name[index] = input.next();
  22. city[index] = input.next();
  23. index++;
  24. }
  25. for(int i = 0 ; i<index;i++) {
  26. if(city[i].equals("Seattle")) {
  27. numPeople[0]+= 1;
  28. nameList[0]+= name[i]+"\n";
  29.  
  30. }
  31. else if(city[i].equals("Yakima")) {
  32. numPeople[1]+= 1;
  33. nameList[1]+= name[i]+"\n";
  34. }
  35. else if(city[i].equals("LaPush")) {
  36. numPeople[2]+= 1;
  37. nameList[2]+= name[i]+"\n";
  38. }
  39. else if(city[i].equals("Everett")) {
  40. numPeople[3]+= 1;
  41. nameList[3]+= name[i]+"\n";
  42. }
  43.  
  44. }
  45. System.out.println(city[0] + " students: "+numPeople[0]);
  46. System.out.println(nameList[0]);
  47. System.out.println(city[1] + " students: "+numPeople[1]);
  48. System.out.println(nameList[1]);
  49. System.out.println(city[2] + " students: "+numPeople[2]);
  50. System.out.println(nameList[2]);
  51. System.out.println(city[3] + " students: "+numPeople[3]);
  52. System.out.println(nameList[3]);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement