Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 lines1 = new ArrayList<>(); int [] lines2; 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 gradeWnated = lines3; CalculateStudyHours(lines3); }//End of while loop }//End of option B public static ArrayList CalculateStudyHours(ArrayList grade) { double studyHours; //Create Studyhours list double [] studyHoursList; while(grade.hasNextLine()){ if( grade == 'F' ) {//If test score Ave is under 60 studyHours = 0;//then letter grade is F studyHoursList.length(); }//End of if loop else if ( grade == 'D' ) { studyHours = 0;/ studyHoursList.length(); }//end of else if loop else if ( grade == 'C' ) { studyHours = 9; studyHoursList.length(); }//end of else if loop else if ( grade == 'B') {//If test score Ave is under 90 studyHours = 12; studyHoursList.length(); }//end of else if loop else if (grade == 'A') {//If test score Ave is under/equal to 100 studyHours = 15; studyHoursList.length(); }//end of else if loop return studyHoursList; } }

}// 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions