I created a text file called studs.txt with the info as follows
1000 john-doe
3000 jane-smith
2000 kevin-khan
and another file reg.txt with the info as follows:
1000 info-2415 info-2420 comp-2700
3000 comp-2500 math-2120 comp-3000 math 2160
I have to create a class called student, and the student object should know all the courses for which he/ she is registered for.
I am not to sure how to go about this but here is what I attempted
import java.util.*;
import java.io.*;
public class Student {
private long studId;
private String studName;
private String courses;
String Max_courses[];
private static final int Max=4;
public Student(long id, String name, String cr) {
studId=id;
studName= name;
courses=cr;
Max_courses= new String[Max];
}
// Accessors for state variables
public long getStudentId() {
return studId;
}
public String StudentName() {
return studName;
}
public String StudentCourses() {
return courses;
}
// mutator to change state information if needed
public void setCourses(String cr) {
courses=cr;
}
public void Registered(String fileName) throws IOException {
Scanner in= new Scanner(new File("reg.txt"));
while (in.hasNext() ) {
long ano= in.nextLong();
String courses= in.next();
for(int i=0;i<Max;i++){
Max_courses[i]=courses;
courses= Max_courses[i];
}
}
}
Please help me and show me where I went wrong!! Thank you!
This post has been edited by macosxnerd101: 16 October 2011 - 08:12 AM
Reason for edit:: Added code tags

New Topic/Question
Reply



MultiQuote





|