Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The error I'm getting after inputing 1 line:
- C:\Users\Eimhin\College>java Directory
- test test 123
- Exception in thread "main" java.lang.NullPoin
- at Population.fill(Directory.java:26)
- at Directory.main(Directory.java:76)
- The program:
- class Person
- {
- String forename;
- String surname;
- int number;
- void getPerson()
- {
- forename = Console.readToken();
- surname = Console.readToken();
- number = Console.readInt();
- }
- void putPerson()
- {
- System.out.println(surname + ", " + forename + "\t" + number);
- }
- }
- class Population
- {
- Person[] group = new Person[1000];
- int i = 0;
- void fill()
- {
- while (!Console.endOfFile())
- {
- group[i].getPerson();
- i++;
- }
- }
- void swap(int j, int k)
- {
- Person tmp = new Person();
- tmp = group[k];
- group[k] = group[j];
- group[j] = tmp;
- }
- void sort()
- {
- int j = 0;
- int k = 0;
- int min = 0;
- while(j < i)
- {
- min = j;
- while(k < i)
- {
- if(group[min].surname.equals(group[k].surname))
- {
- if(group[min].forename.compareTo(group[k].forename) > 0)
- min = k;
- }
- else if(group[min].surname.compareTo(group[k].surname) > 0)
- min = k;
- k++;
- }
- swap(j, min);
- j++;
- }
- }
- void display()
- {
- for(int j = 0; j < i; j++)
- group[j].putPerson();
- }
- void sortThenDisplay()
- {
- sort();
- display();
- }
- }
- class Directory
- {
- public static void main(String[] args)
- {
- Population phonebook = new Population();
- phonebook.fill();
- phonebook.sortThenDisplay();
- }
- }
Add Comment
Please, Sign In to add comment