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-
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.
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-
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-