Results 1 to 3 of 3
  1. #1
    Gsangha is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default Need help with my methods

    Hello and happy new year!,

    The purpose of this code is to calculate gpa. (unfortunately I haven't gotten to the calculation part because I can't get past organizing the input from the user)
    A guide through this code is provide in the comments before the code actually starts.

    My main problem is that I keep getting an error on line 37 and 76 (aka my doubleCheck method); and also when the program starts the promptCourses and promptGrades don't really do their job of getting information from the user.

    I provided the output after the code.

    Any advice?

    Java Code:
    /*Display a prompt that explains how to use the gpa calculator
     * Using a method obtain all the courses the student has taken and store them in an ArrayList.
     * Using a method obtain the grades for the courses the student has taken.
     * Ask the user to double check his or her work after displaying the grades and courses in a chart form. 
    //import packages required for program to run
    import java.util.ArrayList;
    import java.util.Scanner; 
    public class gpaCalculator {
    	public static void main(String[] args){ 
    		Scanner input = new Scanner(; 
    		//Amount of points per letter grade 
    		double A = 4.0;
    		double Bplus = 3.5; 
    		double B = 3.0;
    		double Cplus = 2.5; 
    		double C = 2.0; 
    		double D = 1.0;
    		double F = 0.0;
    		// Directions 
    		System.out.println("Enter a course that you have completed when you are asked for Course.  Type DONE when you have inputted all your classes:  "); 
    		System.out.println("When asked for a Grade" + "\n Type:" + "\n 90 for A" +  "\n 85 for B+" +  "\n 80 for B" +  "\n 75 for C+" +  "\n 70 for C" + "\n 65 for D" + "\n 00 for F");
    		String answer = "NO"; 
    			//make a method to re-prompt the user for information 
    			ArrayList<String> CourseList = promptCourses(); 
    			ArrayList<Integer> Grades = promptGrades(CourseList);
    			doubleCheck(CourseList, Grades); 
    			System.out.print("Are the grades states above correct?"); 
    			answer = input.nextLine(); 
    public static ArrayList<String> promptCourses () {
    	Scanner input = new Scanner(; 
    	ArrayList<String> courseList = new ArrayList<String>(); 
    	//Prompt and Store courses in Array courseList
    		for(int counter = 0; counter < courseList.size(); counter++){
    			System.out.print("Enter a course: " ); 
    			String course = input.nextLine(); 
    		return courseList; 
    public static ArrayList<Integer> promptGrades (ArrayList<String> X) {
    	Scanner input = new Scanner(; 
    	ArrayList<Integer> grades = new ArrayList<Integer>(); 
     	//Prompt and Store Grades in Array grades
    		for(int counter = 0; counter < X.size() -1; counter++){
    			System.out.print("What was your grade for " + X.get(counter)); 
    			int gradeNum = input.nextInt(); 
    		return grades; 
    public static void doubleCheck(ArrayList<String> Y, ArrayList<Integer> Z){
    	//Remove done from Array courseList 
    	//Ask user to double check grades and classes 
    			System.out.println("Please double check your grades" + "\nCouse \t Grade"); 
    			for(int counter = 0; counter < Y.size(); counter++){
    				System.out.println(Y.get(counter) + "\t" + Z.get(counter)); 

    Java Code:
    Enter a course that you have completed when you are asked for Course.  Type DONE when you have inputted all your classes:  
    When asked for a Grade
     90 for A
     85 for B+
     80 for B
     75 for C+
     70 for C
     65 for D
     00 for F
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
    	at java.util.ArrayList.remove(
    	at gpaCalculator.doubleCheck(
    	at gpaCalculator.main(

  2. #2
    Gsangha is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default Re: Need help with my methods

    I managed to find my mistake... I was missing a = sign in my promptCourses method which messed everything up.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Rep Power

    Default Re: Need help with my methods

    Good show! Could you mark the thread as solved please? Take care!

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Java Noob, trying to call methods from another methods
    By gabrielpr12 in forum New To Java
    Replies: 8
    Last Post: 11-17-2011, 10:07 PM
  3. Replies: 1
    Last Post: 10-23-2011, 12:37 PM
  4. Replies: 1
    Last Post: 10-05-2011, 12:15 AM
  5. Replies: 4
    Last Post: 04-03-2009, 06:36 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts