Question
I'm trying to take an ArrayList that has letter grades in it and run it through an if loop to see how many study hours
I'm trying to take an ArrayList that has letter grades in it and run it through an if loop to see how many study hours a student needs. Then I would take those study hours and append/write to a new list.
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
}// End of class
I did something similar in python last year:
GradeWanted = (StudentRecordsList[2::3])
HoursPerClassList = [] for Grade in GradeWanted: if Grade.upper() == 'F': HoursPreClass = 0 HoursPerClassList.append(HoursPreClass) elif Grade.upper() == 'D': HoursPreClass = 6 HoursPerClassList.append(HoursPreClass) elif Grade.upper() == 'C': HoursPreClass = 9 HoursPerClassList.append(HoursPreClass) elif Grade.upper() == 'B': HoursPreClass = 12 HoursPerClassList.append(HoursPreClass) elif Grade.upper() == 'A': HoursPreClass = 15 HoursPerClassList.append(HoursPreClass)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started