Results 1 to 12 of 12
Thread: Test score average
- 10-09-2008, 05:37 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
Test score average
I have to write a program that reads a student's name together with his test scores. Then i have to compute the average for each student. I must make a void method to calculate the average then a value returning method to determine the students grade. How do i combine the name with the average when reading the scores from a text file?
-
Much depends on how the data is laid out in the text file. That will determine how you read in the data. next you probably want to create a Student class that holds the name String and the numeric data that is read in for each student.
- 10-09-2008, 05:53 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
each line is the last name then five scores, such as:
Johnson 85 76 88 90 67
- 10-09-2008, 05:55 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
SO you have a line of text simply. Need to separate them each depends on the space character within each two segments.
-
I would use a Scanner object to read in each line of the file and put it into a String. I'd then call split(" ") on the same String to split it into a array of 6 small Strings (tokens), the name and the 5 test scores. I'd then create a new Student object and place this data, the name String, and the parsed int scores into the new student object, then place this student object into a collection such as an arraylist,.....
- 10-09-2008, 06:04 AM #6
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
the problem is i havent learned split yet but we have just learned StringBuffer. Would i be able to use that some how?
- 10-09-2008, 06:27 AM #7
Member
- Join Date
- Oct 2008
- Posts
- 16
- Rep Power
- 0
im so lost right now, trying to learn this chapter on methods and write this program is starting to feel hopeless
- 10-09-2008, 06:32 AM #8
Senior Member
- Join Date
- Sep 2008
- Posts
- 564
- Rep Power
- 5
Are you not allowed to independently look up methods to use?
If you can't use split(), then I'm assuming you can't use charAt() (since they're both methods of String), which pretty much means you can't do your project.
- 10-09-2008, 06:37 AM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Can you show your code, what you have done so far. The way Fubarable explain is the most perfect way for me.
- 10-09-2008, 08:43 AM #10
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
I die a little on the inside...
Every time I get shot.
- 10-17-2008, 02:56 AM #11
Member
- Join Date
- Oct 2008
- Posts
- 15
- Rep Power
- 0
sir.. do you have any codes for this.. because we have the same problem..:confused::confused: please?
- 10-17-2008, 05:49 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Calculate Average
By sthack99 in forum New To JavaReplies: 4Last Post: 06-13-2008, 11:09 AM -
Test Advisory Panel-Telecommute- Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04-05-2008, 12:38 AM -
show a high score from tetris
By stessie in forum Java AppletsReplies: 0Last Post: 03-19-2008, 03:00 AM -
get the average and maximum score
By Eric in forum Advanced JavaReplies: 2Last Post: 07-01-2007, 04:15 AM -
Klaverjas Score 0.2
By levent in forum Java SoftwareReplies: 0Last Post: 05-23-2007, 07:40 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks