File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes accepting user input into into an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "accepting user input into into an array" Watch "accepting user input into into an array" New topic
Author

accepting user input into into an array

Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
i'm doing this program for my java class that will sort a list of grades in descending order for a class of students. I have the logic and everything ready to go but am having troubles with one thing. How in the World do I put the input the user enters into an array?
1st - Program Asks for the number of students to be entered. (I put that answer into a for loop).
2nd - Program Asks for First Name
3rd - Program Asks for Second Name
4th - Program Asks for Grade
Then with that info I sort it. I'm writing a student class that will do all of the name and grade information for me but like I said I'm having troubles putting that info into an array. any help would be greatly appreciated.
-mike-
Sayed Ibrahim Hashimi
Ranch Hand

Joined: May 17, 2001
Posts: 148
Originally posted by Mike Pirrone:
How in the World do I put the input the user enters into an array?
1st - Program Asks for the number of students to be entered. (I put that answer into a for loop).
2nd - Program Asks for First Name
3rd - Program Asks for Second Name
4th - Program Asks for Grade
Then with that info I sort it. I'm writing a student class that will do all of the name and grade information for me but like I said I'm having troubles putting that info into an array. any help would be greatly appreciated.
-mike-

How do you want to store this data in an array. Do you want to use a tripple subscripted array, and store the first name as a string, the last name as a string, then the grade as a double? This is a bad idea by the way.
Or do you want to construct an Object that will hold the first name, last name, and the grade then place those objects in an array? This is probably how I would do it
Here's some sample code of how to do it the second way.
You already said that you know how to get the user input, so I won't do that.

There is some dependencies which I didn't describe like having a Student class and having a constructor for that class that takes a String,String,double. But I'm assuming that you can work with that.
Hope this helps.


SCJP 1.4<br /><a href="http://www.cise.ufl.edu/~sih" target="_blank" rel="nofollow">www.cise.ufl.edu/~sih</a>
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What have you tried or thought to try so far?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
my apologies for the delayed response. At first I asked the user to enter the number of students, based on that answer using the readLine method, I was going to put that in a for loop to prompt for the first name, last name, and grade. We are learninga bout declaring an array of objects so this is fairly new to me. I had no idea, you could declare each variable (last, first, grade) into its own array and then sort that, I thought. you had to have a 3 X 3 array like the 2nd post stated. At any rate I was going to put all of that into one big class but my teacher was saying to use a sort class (which I have coded for a selection sort - thats his specification) and a student class which sets the last , first, and grade, then a toString() method to display the array. I'll get started on this and keep you updated on my progress. Thank you for the help and at least getting me started. This is why I find java so fun because its so challening. Later on
-Mike-
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
Since this is an simple array program- why are you using a 3 x 3 array.


Author and Instructor, my book
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
i'm not, im using an array of objects.
Mike Pirrone
Ranch Hand

Joined: Oct 30, 2001
Posts: 33
here is an update. I wrote my class to get the data info and put that into an array. I attempted to write my constructor method for the class called Student and did this

I made the grade an int since we are only using whole numbers. then in side my get info method I am doing the following based on the help I received from a previous post.

everything compiles fine but when I attempt to instansiate an object from this class in my main class I get a "cannot resolve symbol" error. What exactly am I doing wrong? I was thinking I could put the prompt for the number of grades to be entered in the main class and just have the getStudent information mehtod just get the information for the firstname, lastname, and grade and call that mehtod in the for loop for each element of the array. thanks for all the help to at least get me started on this.
-mike-
 
 
subject: accepting user input into into an array
 
Similar Threads
Re: Urgent with this program, Pls help
having problem in verifying a character
Need help with output of a program
How to store ten scores in an array?
Files in program?