I've been stuck for a while now in an issue, and the program is not doing what I believe it should be doing.
When I run the program and it gets to the part where it asks you for the name of the course, the program skips the first iteration, or other depending how many courses were inputted. It only allows for input on the last iteration. For the following for loops, the program skips them without ever allowing in input.
My questions is, are the for loops incorrect or is the the String arrays that are not inputting the information correctly to their subscript?
import java.util.Scanner; //Needed for Scanner class
public class StudentRecords
{
public static void main(String[] args)
{
int courses;
int students;
int[] course = new int[5];
int[] student = new int[5];
double GPA = 0;
String[] courseNumber = new String[5];
double[] creditHours = new double[5];
String[] letterGrade = new String[5];
//Scanner object for user input
Scanner kb = new Scanner(System.in);
System.out.println("This program will help you determine the GPA \n"
+ "for each student entered.");
System.out.println("");
System.out.println("How many student's GPA are you going to calculate?");
System.out.print("Enter amount of students (Maximum of 5 students): ");
students = kb.nextInt();
student = new int[students];
System.out.println("");
for(int index = 0 ; index < student.length; index++)
{
System.out.print("Student " + (index + 1) + " information: ");
System.out.println("");
System.out.print("How many courses did student " +
(index + 1) + " take? ");
courses = kb.nextInt();
course = new int[courses];
for(int i = 0; i < course.length; i++)
{
System.out.println("What is the name of course #" + (i + 1));
courseNumber[i] = kb.nextLine();
}
for(int i = 0; i < course.length; i++)
{
System.out.println("How many credit hours is " + courseNumber[i]);
creditHours[i] = kb.nextDouble();
}
for(int i = 0; i < course.length; i++)
{
System.out.println("What is the final letter grade for " + courseNumber[i]);
letterGrade[i] = kb.nextLine();
}
for( i = 0; i < student.lenght<
}
}
}
P.S. This is the question I am working on:
Write a program with the following inputs, all of which are stored in arrays (size 5). First how many courses the student took that semester (can’t be greater than 5). Store in ARRAYS for each student, the course number/name (for example ICT 435), credit hour ( 1-4), and letter grade(A-F). Determine the GPA for the semester.