I am writing a program that focuses on the concept of inheritance. This program should have a class Student with fields such as ID, name, and address. Two classes should be derived from it - ResearchAssistant and TeachingAssistant. The research assistant should have additional fields of area of research, advisor, research account, and payrate. The teaching assistant should have additional fields as well. In the program one should be able to click on a student in a list and show their information.
sample of a research assistant: 124-16-534 Jeffery Benton 1300 Main St. CS1337,MATH2306,PHYS1211 RA Mathematics George Brice 234-65-896 8.75
I have my classes set up pretty good I think. I just need a little advice on how to go about finishing this. I dont exactly know how to start reading from where I left off in the text file. I know I am going to have to distinguish by type e.g. whether RA or TA.
here are my classes for the Student and ResearchAssistant.
I would suggest you delete the no-args constructors, and insist that every Student object you create have a name and address supplied.
I don't think the readStudents method is an integral part of the Student class; it ought to be moved into a different class. Similarly the List<Student> ought not to be inside the Student class. There are a few minor stylistic things, eg it is not obvious what the AOS parameter means. But otherwise the classes look all right.
Have you been told to use doubles for pay rates? You should never use floating-point arithmetic for money; use BigDecimal or integer arithmetic (demoninated in cents, pennies, etc) instead.
You don't need to worry about accessing those variables from the constructor; the super(studentID, name, address) call in the constructor will do that for you. You have to call the ResearchAssistant constructor in the read() method, it will be something like
Yeah, I have my ResearchAssistant constructor set up that way now. But, it is saying studentID,name,address have private access in Student. Here is my read method.
Ok I am going to post all my classes including my TeachingAssistant and TAClass classes. I do not know if I have everything correct and I am still puzzled on why I am getting the private access error.
Your read method is very confusing. You are creating a Student object, then not doing anything with it, so it will vanish into cyber-limbo until the garbage collector finds it. You cannot get access to the studentID etc fields from a subclass; you would have to use the getStudentID() method instead.
If you are using that read method, there are three places (at least) you could legitimately use it
As part of a constructor, but it will be very difficult to write the super() call as the first line.
In a static factory method which returns the Student object.
In another class, to create a Student object to manipulate. This will probably be easiest for you to implement.
[ December 03, 2008: Message edited by: Campbell Ritchie ]
Yeah in my code I add the student to an ArrayList. However, it does not seem very confusing to me unless I am doing something totally wrong. For, all I am trying to do is read information for each student- whether or not their a TA or RA will determine their parameters. Using the super keyword in the method I am hoping that it picks up form where I left off in the student read method. Again, this may not work at all; however, I really dont know another way of reading in the info from the txt file.
You have got a problem, that you are dependent on the structure of the text file. The tiniest error reading the file, or the smallest change which gets the data in the text file in a different order from what you expect,and your application will fail spectacularly. This shows what a bad idea it can be to become so dependent on text files or similar.
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...