If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

having problem with array of arrays

hi! am quite confused with a program that I need to do. I have to make a program for a collection of basketball players. Each player comes with information like age, name, height, and others. I have to make use of arrays only to store those information. The thing is, I also need to have features like adding records, deleting, searching,displaying. Should I make use of a switch to add these features? I am also having trouble with the adding record feature. Where should I start? Anybody who knows?.. I badly need help....

Do you know how to create a "player" class which would hold the information, or are you looking at the implementation of parallel arrays to hold the information?

If you are planning to have a "team" which is a collection of instances of the "player" class, then the "team" object could use an array to store its player objects. Your player class would know how to construct a player instance, "toString" the players, and how to compare them. Your team class would have the methods for inserting a player into its storage, for finding a player, for deleting the player, for finding the player instance and asking it to display its name or other information.

If you are using parallel arrays, then the different kinds of information for each of the players would be held at the same index of each of the arrays. To assemble the information for player "i", you could then access name[i], address[i], age[i], height[i], weight[i], experience[i], etc.

actually, am still thinking what info that array would be holding...
but can i possibly use class for the "team" and array for information about each players? if that would be the case, how would i display say, all information about a specific player? the thing is, i would have to use arrays for the information and not on the "team".

That is why I asked you how much you know about constructing a class. The topic for this thread refers to "array of arrays" and I don't know if your aim is to implement everything using single dimension and multi-dimension arrays - and that's it - or by a more OOP-based approach which is more often the basis for writing programs in Java.

A Player class would hold information about a particular player and provide methods to manipulate that information:

Then, you make a Team by associating several Players with the team, storing the player objects in an array or other Collection.

If you are limited to the procedural-based approach, only creating arrays which hold data, then let us know that limitation and post some code showing how you are thinking you will approach organizing these arrays (remembering the limitations on arrays)

hi! i get the logic now... actually, i just wanna ask if I need to put a BufferedReader for every method say, the setName(), wherein there should be an input from the user? i actually tried it but there was an error.. something like unreported exception java.io.IOexception; must be caught or declared to be thrown..
thanks for the idea anyway.. it helped a lot.. am almost done with the program....

i mean the getName() method.... not the setName... am stuck with that error... i tried adding catch (IOException e) {} ... the problem now is that it cant find IOException symbol... why is that? do you have any idea?

A BufferedReader is for reading a stream - file or other input stream. You would use one per stream, opening and reading and closing as needed. So you might associate a reader or scanner to the "console" input stream and then open it to read input and then close it - not create a new one.

Normally, a method like "getName()" is a request from a process from outside of the object asking the object to share or report the content of a "private" piece of data. The outsider cannot (should not be able to) manipulate the data directly. You are asking the class to send me the data so that I can use it. Normally the object will already have the data, and will just "return" that data to the calling process. There will not be a stream involved, there won't be any input from the user.

You certainly can structure your program as you want, but normally the process of asking a user for data to be input or reading from a file or other stream occurs in a module of its own and not as a part of a getter. I would think that your "user" will be in the Team class ... that is where method main will be, that will be the spoke at the center of your program. So, inside an instance of Team you don't have access to the data of each player ... you have to ask that instance for the data, you need to provide to the instance's interface the data you want it to store (setter method). You should not be able to manipulate "playerX.firstName" from the Team instance - you would ask the instance to return the firstName by calling playerX.getName() and assigning it to a temporary string variable in the Team instance. No stream involved, no BufferedReader needed.

If you want to read more, search "java getter" in Google and you'll find all sorts of articles from JavaPro and JavaWorld and other sources.

It would be very helpful if you would report what kind of error you are getting (either compiler error or runtime error) and what error is being reported, rather than "I tried the program and it didn't work".

You cannot call non-static methods (instance methods) by making a call to its class. Therefore, your "getter" calls in your main should be
String plate = cw.getPlate();
String brand = cw.getBrand();

etc.

There are a whole slew of problems with your code. Too numerous to work through in bulk through this medium. I suggest you speak with a TA or your instructor to test you on your basic understanding and point out where you need to restructure your code.

First place to work ... starting from the bottom since it is what I see in my window ...
It would be better to have the instances of your coursework class "report themselves" for you, rather than making six calls to get data and six print calls. How nice and easy would it be to make one statement,