Hi guys,

Firstly, thanks for the great community, have been lurking for a while and have picked up a lot of help from existing threads.

I am making a small program which takes some inputs as strings, i then need to display a list of these inputs, be able to delete a specific input.

The basic concept of the program is to add a member to a gym, its very simple, just input the name, memberid and phone number (member Id must be inputable and not auto as it is retrieved by the data inputter fro somewhere else).

I have got the system accepting inputs but i cannot get it to show back a list of inputs.

If I use the following:

System.out.println(Karate.people[1].getInfo());

it will show the first person I have input, but then if I go back to add another person it will still only print that line at the end. When I changed the 1 to i it would not display anything apart from the default values. i is used from here:

public SportActivity(int number){
       for (int i=0; i<number; i++) {
           people[i] = new Person();

       }
       this.number = number;
   }

Any assistance would be greatly appreciated, If you need to see more code then please ask, alternatively if anyone would be so kind as to help over MSN or AIM then it would be very helpful.

Kind regards,

Hi,

System.out.println(Karate.people[1].getInfo());

The above code is doing what it is meant to be. Put it in For loop to loop with other people info.

The below code is initialising people. Give some info about what you are updating and where are you saving it up like in database, or file or it is just a simple program you are doing keeping the value in variable(array in your case) and printing the info.

public SportActivity(int number){
       for (int i=0; i<number; i++) {
           people[i] = new Person();

       }
       this.number = number;
   }

Just thinking you are doing a simple program to take input , printing it and latter having the option to delete some(if you need to keep data use database or file). so my suggestion is make a Structure Here Class as you have People and declare ArrayList you will find more info in java.lang.util folder of documentation. Its a collection. it have various methods like to search for a particular object (in your case lets say you wanted to delete one person you need to find it first). then you can remove it if they exist. its simple to add and delete in ArrayList. More is its Dynamic so no limit on size as well.If you need to save it in database or file you can do so by Its iterator method (for traversing thru array) and make sql command to save in database of file input method to save in file.
Hope it will help you to some extent..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.