I've been reading book algorithms on Java by Robert Lafore. And there is an problem - Object sorting. So there are three classes which make hierarchy. In book it is fine working but in Eclipse I have problem "Implicit super constructor Person() is undefined. Must explicitly invoke another constructor". What shall I do with extentions classes, or what shall I change to make this code run? Please help. Thank you.
class Person {
private String lastName;
private String firstName;
private int age;
public Person(String last, String first, int a) {
lastName = last;
firstName = first;
age = a;
}
public void displayPerson() {
System.out.print("Last name: " + lastName);
System.out.print(". First name: " + firstName);
System.out.println(". Age: " + age);
}
public String getLast() {
return lastName;
}
}
Next class extends person.
public class ArrayInObj extends Person {
private Person a[];
private int nElems;
public ArrayInObj(int max) { // Here is the problem
a = new Person[max];
nElems = 0;
}
public void insert(String last, String first, int age) {
a[nElems] = new Person(last, first, age);
}
public void display() {
for (int i = 0; i < nElems; i++) {
a[i].displayPerson();
}
System.out.println(" ");
}
public void insertionSort( ) {
int in, out;
for (out = 1; out < nElems; out++) {
Person temp = a[out];
in = out;
while (in > 0 && a[in-1].getLast().compareTo(temp.getLast()) > 0) {
a[in] = a[in -1];
--in;
}
a[in] = temp;
}
}
}
And the main class with main function.
public class ObjectSort extends ArrayInObj {
public ObjectSort(int max) {
super(max);
}
public static void main(String[] args) {
int maxSize = 10;
ArrayInObj arr = new ArrayInObj(maxSize);
arr.insert("Evans", "Patty", 24);
arr.insert("Smith", "Lorainne", 37);
arr.insert("Yee", "Tom", 43);
arr.insert("Adams", "Henry", 63);
arr.insert("Hashimoto", "Sato", 21);
System.out.println("Before sorting: ");
arr.display();
arr.insertionSort();
System.out.println("After sorting: ");
arr.display();
}
}