|
|
|
|
 |

July 23rd, 2009, 07:32 AM
|
|
Captain
|
|
Join Date: Jan 2008
Posts: 913
Thanks: 21
Thanked 53 Times in 33 Posts
|
|
Re: O.T Help sought from Java Programmers
First, in the constructor you inverted your assignments - it should be studentID = sId, instead of sId = studentID, etc. Then, your fields should be private. You also need setters. And probably not everything should be a String, but that's less important.
In printDetails() you would use a StringBuilder class to combine all those Strings from fields into one String the method will return.
Enrollment would have one array of Student objects, addStudent() would add a new student to the array and return the index, getStudent() would use the index to retrieve the Student object, printEnrolment would iterate through the array and invoke printdetails on each student and write that to System.out. It would be useful to have a method to return the number of Students as well.
Admin would have the Main method in which he would call filData and then searchStudent in a loop until he gets a result. fillData creates an Enrollment object, then Student object whose data are hardcoded and inputs them into the enrollment using addStudent, then finally printsEnrollment. searchStudent takes a year, then calls getStudent for each Student, takes his year and if it matches prints his data to System.out; it returns true if successful, otherwise false.
Anyway, that's how I understood what you are expected to do. I know it's a total beginner level project, but I think it's very poorly composed.
|
|
The Following User Says Thank You to Psycho For This Useful Post:
|
|

July 24th, 2009, 03:05 AM
|
 |
Sergeant
|
|
Join Date: Dec 2007
Location: WA, Australia
Posts: 228
Thanks: 18
Thanked 7 Times in 5 Posts
|
|
Re: O.T Help sought from Java Programmers
I really want to that you all for your help. I am studying for my degree correspondence because I'm a small town country hick - up to this point I have found external studies suits me fine, but for this unit... someone on hand to converse with is certainly missed.
I have finished the student class (I think) taking onboard your suggestions - public to private, inversion of assignments etc. I know I should get onto the main(), but needed a small win for some confidence, so Student class needed completion.
I still don't know the why and what of get and set methods, but I believe this will become apparent when I start fiddling with the array.
public class Student {
private String studentID;
private String firstName;
private String lastName;
private String gender;
private String dateOfBirth;
private String phoneNumber;
private String yearCommenced;
//Constructor
public Student(String sId, String fn, String ln, String sex, String dOB, String pn, String yc){
studentID = sId;
firstName = fn;
lastName = ln;
gender = sex;
dateOfBirth = dOB;
phoneNumber = pn;
yearCommenced = yc;
}
//Get methods
public String getStudentID(){
return studentID;
}
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getGender(){
return gender;
}
public String getDateOfBirth(){
return dateOfBirth;
}
public String getPhoneNumber(){
return phoneNumber;
}
public String getYearCommenced(){
return yearCommenced;
}
//set methods for data fields
public void setStudentID(String sId){
studentID = sId;
}
public void setFirstName(String fn){
firstName = fn;
}
public void setLastName(String ln){
lastName = ln;
}
public void setGender(String sex){
gender = sex;
}
public void setDateOfBirth(String dOB){
dateOfBirth = dOB;
}
public void setPhoneNumber(String pn){
phoneNumber = pn;
}
public void setYearCommenced(String yc){
yearCommenced = yc;
}
}
In the ball park?
|

July 24th, 2009, 03:25 AM
|
|
Sergeant
|
|
Join Date: Dec 2008
Posts: 200
Thanks: 10
Thanked 10 Times in 6 Posts
|
|
Re: O.T Help sought from Java Programmers
Your student class looks good.
Quote:
|
I still don't know the why and what of get and set methods, but I believe this will become apparent when I start fiddling with the array.
|
Unfortunately, it probably won't become apparent. The assignment you've been given is a terrible way to learn the "why" of OOP, since what you've been told to do is code a procedural style program using objects. But no need to worry about that now 
|

July 24th, 2009, 03:45 AM
|
 |
Sergeant
|
|
Join Date: Dec 2007
Location: WA, Australia
Posts: 228
Thanks: 18
Thanked 7 Times in 5 Posts
|
|
Re: O.T Help sought from Java Programmers
Quote:
Originally Posted by statttis
Your student class looks good.
Quote:
|
I still don't know the why and what of get and set methods, but I believe this will become apparent when I start fiddling with the array.
|
Unfortunately, it probably won't become apparent. The assignment you've been given is a terrible way to learn the "why" of OOP, since what you've been told to do is code a procedural style program using objects. But no need to worry about that now 
|
God help me... 
|

July 24th, 2009, 03:54 AM
|
|
Sergeant
|
|
Join Date: Dec 2008
Posts: 200
Thanks: 10
Thanked 10 Times in 6 Posts
|
|
Re: O.T Help sought from Java Programmers
Quote:
Originally Posted by hEad
God help me... 
|
As I said, don't worry about it now
Your next step is to write the Enrollment class. It will have the three methods and a list of students. I recommend using a Vector for the list.
You can use the vector as so:
Vector students = new Vector();
then use the methods add() and remove() to add and remove students:
students.add(*student object*)
etc
That should be enough to get you started.
|

July 24th, 2009, 06:28 AM
|
|
Captain
|
|
Join Date: Apr 2004
Location: France
Posts: 820
Thanks: 4
Thanked 33 Times in 24 Posts
|
|
Re: O.T Help sought from Java Programmers
Your student class is fine.
The get/set usefulness will appear when you change the implementation. For instance, gender can only be 'male' or'female'. So when someone wants to set or change the gender of a student, you can check in the setGender method that he's putting 'male' or 'female', and refuse to do anything, throw an error or react however you like if they try to say setGender( "42" ). IF you leave the data public, you can have all kinds of spurious values in your fields.
Quote:
|
I recommend using a Vector for the list.
|
Note the assignment says array. I'd go with a Vector (or List) too, because using a java array would be totally stupid in this context. I suppose "array" was ment as a general term and not the [] thing.
|

July 24th, 2009, 07:10 AM
|
|
Captain
|
|
Join Date: Jan 2008
Posts: 913
Thanks: 21
Thanked 53 Times in 33 Posts
|
|
Re: O.T Help sought from Java Programmers
Using the List or Vector beats the point of the existence of the Enrollment class in the first place. I am pretty sure the intent was to make him create his own Vector class (with the name Enrollment). It's really not a very good project.
For gender the best way is to create an enum if Java supports those. Or a couple of constants and make the field int.
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is On
|
|
|
|
|