![]() |
Re: O.T Help sought from Java Programmers
Natpy is currently studying Java so he kindly agreed to do this exercise for you. After that I will check what he wrote and maybe correct errors if there're any.
All should be done by tomorrow evening. |
Re: O.T Help sought from Java Programmers
Quote:
|
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? |
Re: O.T Help sought from Java Programmers
Your student class looks good.
Quote:
|
Re: O.T Help sought from Java Programmers
Quote:
|
Re: O.T Help sought from Java Programmers
Quote:
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<Student> students = new Vector<Student>(); 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. |
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:
|
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. |
Re: O.T Help sought from Java Programmers
Of course using a string for gender is not great. A boolean would do the job, or a class with two fixed instances and a private constructor rather than an enum. But then IRL you would store that info in a database anyway.
Hand-writing an array with proper memory management is just a pain and probably beyond the OP's skills right now, so he's better off using a List to begin with in my opinion. It's also a rather useless exercise in java. It's great in C, but in java it's just silly as you could copy-paste the Vecotr code if you wanted to anyway. |
Re: O.T Help sought from Java Programmers
1 Attachment(s)
Here
|
All times are GMT -4. The time now is 01:36 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.