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
//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
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
Get step-by-step solutions from verified subject matter experts
