rampmonkey
12-27-2005, 03:59 PM
Hey, ok well im trying to create a kind of phone book in java. I have created an array of objects, each as a contact.
This is a snip from my code
public static void main(String[] args) {
for(int i=0; i < nocont; i++){
mycontact[i] = new Contact(); System.out.println("New Contact"); System.out.print("\nEnter First Name: "); mycontact[i].firstname = UserInput.readString(); int lenfirst = mycontact[i].firstname.length(); if (lenfirst == 0){ System.out.println("ERROR, No first name was entered\n");
break;
The array is 3 in length. The problem is, when you enter the first name, it fills all the array up with the firstname. Therefore you get no unique contacts they are all the very last one you input.
Any help would be greatly accepted!
This is a snip from my code
public static void main(String[] args) {
for(int i=0; i < nocont; i++){
mycontact[i] = new Contact(); System.out.println("New Contact"); System.out.print("\nEnter First Name: "); mycontact[i].firstname = UserInput.readString(); int lenfirst = mycontact[i].firstname.length(); if (lenfirst == 0){ System.out.println("ERROR, No first name was entered\n");
break;
The array is 3 in length. The problem is, when you enter the first name, it fills all the array up with the firstname. Therefore you get no unique contacts they are all the very last one you input.
Any help would be greatly accepted!