Question: Using java I'm trying to write four different array lists to a new file called StudentsHoursGrades.txt. The for array lists are: lines1 (This is the

Using java I'm trying to write four different array lists to a new file called StudentsHoursGrades.txt.

The for array lists are:

lines1 (This is the student's names)

lines2(These are the credits)

study hours(these are the study hours)

lines3(these are the grade)

I want what's written to the file to look something like this:

Aaron Rodgers

12

60

A

Joe Theismann

15

60

B

Philip Rivers

3

15

A

This is what I have so far:

import java.util.ArrayList; import java.util.Scanner; import java.io.*;

public class Project1ReVistC {

public static void main( String [ ] args ) throws FileNotFoundException { MenuOptionB(); }// End of main method3 public static void MenuOptionB() throws FileNotFoundException { File file = new File("Grades.txt"); File fileOut = new File("StudentsHoursGrades.txt"); Scanner scan = new Scanner(file); Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(fileOut); ArrayList lines1 = new ArrayList<>(); ArrayList lines2 = new ArrayList<>(); ArrayList lines3 = new ArrayList<>(); while(scan.hasNextLine()){ //reading the line from the file String line1 = scan.nextLine(); System.out.println(line1); //Ask user if they want to change information System.out.println("Dose this name need to be corrected? 1-yes,any other number-no: "); //Give the user a choice int choice = Integer.parseInt(in.nextLine()); if(choice == 1){ //asking the user to enter a new line System.out.println("Enter a replacement : "); String string = in.nextLine(); //adding to the list lines1.add(string); }//End of if statement else{ //adding the old line to the list lines1.add(line1); }//End of else statement

//Reads credits line in file and displays it String line2 = scan.nextLine(); System.out.println(line2); //Ask user if they want to change information System.out.println("Are these credits disable by 3 and under 15? 1-yes,any other number-no: "); //Give the user a choice int choice = Integer.parseInt(in.nextLine()); if(choice == 1){ //asking the user to enter a new line System.out.println("Enter a replacement : "); String string = in.nextLine(); //adding to the list lines2.add(sting); }//End of if statement else{ //adding the old line to the list lines2.add(line2); }//End of else statement //Reads grade line in file and displays it String line3 = scan.nextLine(); System.out.println(line3); //Ask user if they want to change information System.out.println("Is this grade A-D or F? 1-yes,any other number-no: "); //Give the user a choice int choice = Integer.parseInt(in.nextLine()); if(choice == 1){ //asking the user to enter a new line System.out.println("Enter a replacement: "); String string = in.nextLine(); //adding to the list lines3.add(string); }//End of if statement else{ //adding the old line to the list lines3.add(line3); }//End of else statement ArrayList studyhour = CalculateStudyHours(lines3); }//End of while loop //Me trying to add all the array lists to gether for (lines1+ lines2+ studyhour+ lines3: studentInfor) { } }//End of option B public static ArrayList CalculateStudyHours(ArrayList grades) {

ArrayList studyHoursList = new ArrayList();

for (String grade : grades) {

if (grade == "F") {// If test score Ave is under 60

studyHoursList.add(0.0);

} // End of if loop else if (grade == "D") {

studyHoursList.add(0.0);

} // end of else if loop else if (grade == "C") {

studyHoursList.add(9.0); } // end of else if loop else if (grade == "B") {// If test score Ave is under 90

studyHoursList.add(12.0);

} // end of else if loop else if (grade == "A") {// If test score Ave is under/equal to 100

studyHoursList.add(15.0); } // end of else if loop }

return studyHoursList; }

}// End of class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!