This is my Final Project and as you can see my program asks the users twice for the test grade I am trying to consolodate and have the program only ask for the test score once and give the letter grade at the same time.? any ideas I do not know how to take the input from what is the score for test one and use it with the if else statement. Thank a bunch.

import javax.swing.JOptionPane;  //for the JOptionPane class

    public class Final
   // Main method to start program which will find letter grades
   // for individual tests and also find average letter grade for all 5 tests
       public static void main(String[] args)
   // Method determineGrade used to determine letter grade for a numeric test score and the average test score
       public static void determineGrade()
         int testScore; //Numeric test score
         String input;   //To hold user's input
      //get the numeric test score.
         input = JOptionPane.showInputDialog("Please Re-enter the score to recieve a letter grade.");
         testScore = Integer.parseInt(input);
      //calculate and display the grade.
         if (testScore < 60)
            JOptionPane.showMessageDialog(null, "Your Grade is F.");
         else if (testScore < 70)
            JOptionPane.showMessageDialog(null, "Your Grade is D.");
         else if (testScore < 80)
            JOptionPane.showMessageDialog(null, "Your Grade is C.");
         else if (testScore < 90)
            JOptionPane.showMessageDialog(null, "Your Grade is B.");
         else if (testScore <= 101)
            JOptionPane.showMessageDialog(null, "Your Grade is A.");
         else					//Invalid score
            JOptionPane.showMessageDialog(null, "Invalid score.");
   /** Method used to take in scores of the 5 test and then calculate the average test score
   The Method calcaverage contains the method determineGrade in it to show the numeric score into a letter grade.
       public static void calcaverage()
         double test1;	// test 1 score
         double test2;	// test 2 score
         double test3;	// test 3 score
         double test4;	// test 4 score
         double test5;  // test 5 score
         double average;  // average of all 5 tests
         String input;    	//to hold users input
      // get test1 score
         input = JOptionPane.showInputDialog("What is the score for test 1?");
         test1 = Double.parseDouble(input);
      //get test2 score
         input = JOptionPane.showInputDialog("What is the score for test 2");
         test2 = Double.parseDouble(input);
      //get test3 score
         input = JOptionPane.showInputDialog("What is the score for test 3");
         test3 = Double.parseDouble(input);
      //get test4 score
         input = JOptionPane.showInputDialog("What is the score for test 4");
         test4 = Double.parseDouble(input);
      //get test5 score
         input = JOptionPane.showInputDialog("What is the score for test 5");
         test5 = Double.parseDouble(input);
      //calulate Average
         average = (test1 + test2 + test3 + test4 + test5) / 5;
      //display average
         JOptionPane.showMessageDialog(null, "The average test score is " + average);

Make determineGrade() a function that takes the test score as a parameter and returns the letter for the grade. Honestly, if this is a "final" you really should already know how to write a function.

thanks that helps. I sorry I forget things, this is not my only final i have other classes and get stressed this is also my first computers class. Thank you again though

I just want to apologize, I kinda acted a little rude. I did what you said ( i admit it is a little dumb I did not think of that, I think i missed that day) I now know though. Thank you so much.

~ Generalcoco

This question has already been answered. Start a new discussion instead.