Question:
java help!!!!!! *urgent*?
ma3088
2008-04-28 13:23:40 UTC
Write a program that reads student data from a file selected by the user and creates the file specified by the user containing a report listing the students and the letter grades they earned in the course.

the file has data like this...
u07723-23
Van Pelt
Jacob
34.0
45.0
12.0
12.0
34.0
45.0
65.0
34.0
56.0
u00232-45
and so on...

i've of course gotten the program to ask the user the file name and whether or not he or she wants to overwrite it. I need help with the methods?? Can we pass files onto methods?

Some hints or examples would be good. thanks.
Four answers:
2008-04-28 13:39:31 UTC
You may contact a java helper live at website like

http://ccietutorial.com/
SPB
2008-04-28 13:38:21 UTC
I think you will need a Student class. The Student class will have variables for id, lastName, firstName, scores. scores can be a collection of some sort based on what you want to do with it.



I think you should have a Course class. The Course class will have a collection of Student objects.



You main program will create the Course object. It will then read the file, one line at a time. If you read a line starting with u0 then assume it is a new student. Instantiate a Student object passing the id on the constructor. Read the next line from the file. Set the lastName in the Student object. Read the next line. Set the firstName. Read lines until you reach another u0 line. As you read each line, add each grade to the Student object. Now, Add the Student object to the Course object. Start over...a while loop probably.



So Student has

String id;

String lastName;

String firstName;

Collection scores;



public void setId(String anId)

public void setLastName(String name)

public void setFirstName(String name)

public void addScore(String score)



The Course class has

Collection students;



public void addStudent(Student aStudent)

public void computeGrades()



Or something like that. I think you get the idea.
Jim Maryland
2008-04-28 13:37:39 UTC
Are you just reading from one file and writing it out to another? If so, I'd make a file utility class that contains a method called copy and have it take two File parameters



public class FileUtility {

public boolean lineCopyFile(File infile, File outfile) {

// code to read from one and write to the other

}
kchorn
2008-04-28 13:46:25 UTC
Here's a good link on java file io:

http://www.leepoint.net/notes-java/io/10file/10readfile.html



The rest of the website itself is also a great resource for Java:

http://www.leepoint.net/notes-java/index.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...