Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. The error I'm getting after inputing 1 line:
  2.  
  3. C:\Users\Eimhin\College>java Directory
  4. test test 123
  5. Exception in thread "main" java.lang.NullPoin
  6.        at Population.fill(Directory.java:26)
  7.        at Directory.main(Directory.java:76)
  8.  
  9. The program:
  10.  
  11. class Person
  12. {
  13.     String forename;
  14.     String surname;
  15.     int number;
  16.     void getPerson()
  17.     {
  18.         forename = Console.readToken();
  19.         surname = Console.readToken();
  20.         number = Console.readInt();
  21.     }
  22.     void putPerson()
  23.     {
  24.         System.out.println(surname + ", " + forename + "\t" + number);
  25.     }
  26. }
  27. class Population
  28. {
  29.     Person[] group = new Person[1000];
  30.     int i = 0;
  31.     void fill()
  32.     {
  33.         while (!Console.endOfFile())
  34.         {
  35.            
  36.             group[i].getPerson();
  37.             i++;
  38.         }
  39.     }
  40.     void swap(int j, int k)
  41.     {
  42.         Person tmp = new Person();
  43.         tmp = group[k];
  44.         group[k] = group[j];
  45.         group[j] = tmp;
  46.     }
  47.     void sort()
  48.     {
  49.         int j = 0;
  50.         int k = 0;
  51.         int min = 0;
  52.         while(j < i)
  53.         {
  54.             min = j;
  55.             while(k < i)
  56.             {
  57.                 if(group[min].surname.equals(group[k].surname))
  58.                 {
  59.                     if(group[min].forename.compareTo(group[k].forename) > 0)
  60.                         min = k;
  61.                 }
  62.                 else if(group[min].surname.compareTo(group[k].surname) > 0)
  63.                     min = k;
  64.                 k++;
  65.             }
  66.             swap(j, min);
  67.             j++;
  68.         }
  69.     }  
  70.     void display()
  71.     {
  72.         for(int j = 0; j < i; j++)
  73.             group[j].putPerson();
  74.     }
  75.     void sortThenDisplay()
  76.     {
  77.         sort();
  78.         display();
  79.     }
  80. }
  81. class Directory
  82. {
  83.     public static void main(String[] args)
  84.     {
  85.         Population phonebook = new Population();
  86.         phonebook.fill();
  87.         phonebook.sortThenDisplay();
  88.     }
  89. }
Add Comment
Please, Sign In to add comment