My assignment is to, using methods, get information from a text file with an ID number and scantron values for answers that that student made.
I must then calculate their scores and such.
It's just this first method is killing me.
I don't know what it should return and I don't know how to make it return it.
I will need to separate each of the 15 answers into 15 individual answers, I think, but I don't know how to do that. There is no space in between them. The text file reads like this:
The number before the comma is the ID and the number after is the series of answers.The number before the comma is the ID and the number after is the series of answers.Code:4563123,112211324135412 2312311,222121324135211 2312345,112211324135421 5527687,212111313124412 7867567,111111111111111
How can I separate each of those?
This is what I have:
Code:public static String fileStuff () throws IOException { Scanner s = new Scanner(System.in); System.out.println("What is the name of the file?"); File fileName = new File (s.nextLine()); Scanner inFile = new Scanner(fileName); if (fileName.exists()){ File results = new File ("results.txt"); FileWriter fw; fw = new FileWriter(results, true); PrintWriter outFile = new PrintWriter ("results.txt"); PrintWriter outputFile = new PrintWriter(fw); String [][] answers = new String [50][50]; while (inFile.hasNext()){ String line = inFile.nextLine(); String [] pieces = line.split(","); for (int x = 0; x < pieces.length -1; x++){ // if(x+1<pieces.length){ String [] WID = new String [50]; answers[x][x+1] = pieces [x+1]; WID [x] = pieces[x]; //print WID outputFile.println("WID: " + WID [x]); //Print answers outputFile.println(answers[x][x+1]); outputFile.println(" "); // }// end if /* String trueOrFalse = answers[x+1].substring(0,6); String multipleChoice = answers[x+1].substring(6,15); String trueOrFalse0 = trueOrFalse.substring(0,1); String trueOrFalse1 = trueOrFalse.substring(1,2); String trueOrFalse2 = trueOrFalse.substring(2,3); String trueOrFalse3 = trueOrFalse.substring(3,4); String trueOrFalse4 = trueOrFalse.substring(4,5); */ }// end for } System.out.print(answers[0][3]); inFile.close(); outFile.close(); outputFile.close(); return (""); } //end if else { System.out.append("File does not exist! Try again:"); return ("");} } //end fileReader public static void printGrade (char a){ System.out.println("Grade: " + a + "\n"); } public static int numberCorrect (int number){ //grade a single quiz and return numberCorrect return(0); }// grade static void average (int h ){ //calculate and return average return; }//average static void display (int h ){ //display return; } static void sort (int [ ] n) { return; } //end swap }
1. How can I make each answer its own string?
2. How can I get this method to return all of those strings for calculation in another method?