Hi, I have this little program with two classes in it. The first class Kontakt (Contact in english) contains information about a person (name,surname and number). Now, in the PhoneBook class I am trying to implement a LinkedList <Kontakt>, i.e. a list of contacts. Now, all the methods work fine, but when I try to print it out, I get weird strings, something like addresses of the objects. I really do not know where the problem. Here is my code. Thank you for any help in advance.
The first class Kontakt.
public class Kontakt {
String name,surname;
int number;
public Kontakt (String name, String surname, int telBroj){
this.name = name;
this.surname = surname;
this.number = number;
}
public String getName() {
return name;
}
public String getSurname() {
return surname;
}
public int getNumber() {
return number;
}
}
And the second class PhoneBook.
import java.util.*;
/*class Jazol {
Kontakt element;
Jazol succ;
public Jazol(Kontakt element, Jazol succ) {
this.element = element;
this.succ = succ;
}
}*/
public class PhoneBook {
private LinkedList<Kontakt> list;
public PhoneBook(){
list = new LinkedList<Kontakt>();
}
public static void main(String [] args) {
Iterator iterator;
Kontakt robert = new Kontakt("Robert","Gliguroski",12);
Kontakt bozidar = new Kontakt("Bozidar","Menkinoski",13);
Kontakt pepi = new Kontakt("Pepi","Bogdanoski",14);
LinkedList<Kontakt> list = new LinkedList<Kontakt>();
list.addFirst(robert);
list.add(bozidar);
int size = list.size();
iterator = list.iterator();
while(iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
System.out.println();
System.out.println("List's length " + size);
iterator = list.iterator();
while(iterator.hasNext()){
System.out.print(iterator.next() + " ");
}
}
}