GradeQuiz File Input Example
Describes how to read and score student quiz results where students submitted text-only files to a common handin folder.
Quiz Questions
- What is your login name?
- What is Deb's email address
- What is the sum of 4 + 47.3?
Text-only File Format that our program will read
1. login_name
2. email_address
3. value
File System - directory structure for our student quiz files
handin/
handin/deppeler.quiz1
handin/hasti.quiz1
handin/skrentny.quiz1
To create folders or text-only data files in Eclipse
- Open Eclipse
- Select (highlight) the project that will need to read the file
- Select File from the menu bar.
- Select New from the File menu.
4.a) Create a Folder
- Select Folder
- Type a name for the folder. (ie.
handin
)
- Press Enter keyto save the newly created folder.
4.b) Create a text-only file
- Select Untitled text file to create a text-only file.
- Type the contents of the file (student's answers) in the file editor window. Follow the file format above if you want to read the file with the example code.
- Select File -> Save As
- Select the folder (ie. the
handin
folder you just created)
- Type the name of the file.
- Press Enter to save the newly created file.
class GradeQuiz (PSEUDOCODE)
- main method
- create roster_list of student logins
- for each student:
- create filename based on path, login, file extension
- open file (create a Scanner connected to the student's file)
- read file and save file contents
- close file
- grade file contents
- display score
- readAllLines(Scanner connected to a file) method
- while still more lines in the scanner
- read and save line with other lines
- return array of lines that were read
- grade(contents of a file - array of Strings)
- if first answer matches the login name, score plus one
- if second answer matches deb's email, score plus one
- convert last answer to double
- if difference between last answer as double is close enough to sum, score plus one
- return score
coded Examples:
- GradeQuiz_001.java - class GradeQuiz_001.java (program created in Lecture 001 using ArrayList)
- GradeQuiz_002.java - class GradeQuiz_002.java (program created in Lecture 002 using String and split("\n") method
© 2014 Debra Deppeler, All rights reserved.