Well, school starts up again, been a few years since I did anything serious with Java, and I'm afraid my memory/coding abilities are a bit rusty. Been running into a few problems, was hoping anyone who is familiar with coding in Java would be able to help answer some questions as I come up with them.
Anyway, I'll start off with my initial problem, and work from there if/when my questions can be answered.
1.
My first problem, concerns objects, creating an array of objects, and then actaully using methods on those. Allow me to be a bit more specific with coding and my actual problem.
The idea is to create an object student, and then an array we'll call listOfStudents. I need to be able to create a new student and add it to listOfStudents. I think I may have got the general idea of how to go about that, but my main problem comes from when you utilize different classes to perform specific methods in the main.
Apologies for the rather weak, crumby, or massively faulty code. Like I said, it's been a few years since I did any coding, and I didn't do much back then anyway, so I hope someone can understand what I'm trying to do with it, give me pointers, and correct my numerous errors I'm sure I have.
student class
listOfStudents class
main class
Thoughts on where to start?
The only part that won't compile is this line
which leaves me with my problem at hand. How exactly do I go about doing this? At this point in time, I'm at a loss. Perhaps my student isn't compatable with my array for students, perhaps it's because of how I set up my classes, etc. I just don't know. I have a hunch that it's something to do with me trying to call an object/method incorrectly, or some such. Perhaps I'm trying to do it in the wrong place, or perhaps I'm doing it wrong altogether.
Anyways, please post any thoughts you can, and ask me questions, and I'll better explain what I'm trying to do if it's not clear.
It's so basic I know, and yet I just can't remember how to handle it. I'm afraid I've forgotten what belongs where.
Thanks in advance.
Anyway, I'll start off with my initial problem, and work from there if/when my questions can be answered.
1.
My first problem, concerns objects, creating an array of objects, and then actaully using methods on those. Allow me to be a bit more specific with coding and my actual problem.
The idea is to create an object student, and then an array we'll call listOfStudents. I need to be able to create a new student and add it to listOfStudents. I think I may have got the general idea of how to go about that, but my main problem comes from when you utilize different classes to perform specific methods in the main.
Apologies for the rather weak, crumby, or massively faulty code. Like I said, it's been a few years since I did any coding, and I didn't do much back then anyway, so I hope someone can understand what I'm trying to do with it, give me pointers, and correct my numerous errors I'm sure I have.
student class
Code:
package practice;
public class student {
/** Creates a new instance of student */
public student(String studentName, int studentID, String email, String phoneNumber) {}
}
listOfStudents class
Code:
package practice;
public class listOfStudents {
private int size = 100;
private int count = 0;
public student[] studentList;
/**
* Creates a new instance of listOfStudents
*/
public listOfStudents() {
studentList = new student[size];
}
public void addStudent(student newStudent){
if( count != size){
studentList[count] = newStudent;
count = count+1;
}
else{
System.out.println("The Array is Full!");
}
}
}
main class
Code:
package practice;
public class Main {
/** Creates a new instance of Main */
public Main() {
}
public static void main(String[] args){
student s1 = new student("John", 1234, "[email protected]", "800-9000");
studentList.addStudent(s1);
}
}
Thoughts on where to start?
The only part that won't compile is this line
Code:
studentList.addStudent(s1);
Anyways, please post any thoughts you can, and ask me questions, and I'll better explain what I'm trying to do if it's not clear.
It's so basic I know, and yet I just can't remember how to handle it. I'm afraid I've forgotten what belongs where.
Thanks in advance.