# Help with Control statements/methods!!

• September 6th, 2011, 03:41 PM
gpelefty90
Help with Control statements/methods!!
Hi, I am having trouble figuring out how to put all of this code together since it combines methods and if else statements. I was wondering if anyone could help me out. Here is the problem:

Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. In addition to the main method, write the following methods in the program:
• calcAverage – This method should accept five test scores as arguments and return the average of the scores.
• determineGrade – This method should accept a test score as an argument and return a letter grade for the score, based on the following grade scale A=100-90 , B=89-80, C=79-70, D=69-60, F= below 60.

Thanks!!
• September 6th, 2011, 04:16 PM
Norm
Re: Help with Control statements/methods!!
• September 6th, 2011, 04:25 PM
gpelefty90
Re: Help with Control statements/methods!!
yes, i know how to create the two sub methods but what i am confused about is how to create the main method to pass it to the two sub methods.
• September 6th, 2011, 04:29 PM
Norm
Re: Help with Control statements/methods!!
Quote:

how to create the main method to pass it to the two sub methods.
I'm not sure of your terminology. The "pass it to" part is confusing.
The main method would call the two sub methods and pass them the necessary values as arguments.
• September 6th, 2011, 04:37 PM
gpelefty90
Re: Help with Control statements/methods!!
I apologize for the confusion. but yes that is what i ment. I am confused on how to construct the main method in order for it to call the two sub methods and pass them the arguments
• September 6th, 2011, 04:40 PM
Norm
Re: Help with Control statements/methods!!
Assuming you have the arguments: arg1, arg2, ...

You call a method: methodName(arg1, arg2, ...);

Replace the ... with more args or remove them.

Put that code inside of the main method.
• September 6th, 2011, 04:42 PM
Norm
Re: Help with Control statements/methods!!
For more info on how to use methods see the Tutorial. Go to this site and Find methods:
• September 6th, 2011, 04:47 PM
gpelefty90
Re: Help with Control statements/methods!!
and then you write that methodName outside the main method and describe what the method should be calc. right?
• September 6th, 2011, 05:02 PM
Norm
Re: Help with Control statements/methods!!
Yes, you define the methods outside of the main method.
No method can be defined inside of another method.
• September 6th, 2011, 05:07 PM
gpelefty90
Re: Help with Control statements/methods!!
I have written my code and almost everything is write except i can not get the determineGrade method to work. the calcAverage method works great but i can not get the other method to work.

here is my code:

package review_package;
import
javax.swing.JOptionPane;
public class REVIEW_prog_Gaines_Elmore {

/**
* @param args
*/
public static void main(String[] args) {
String x=JOptionPane.showInputDialog(
"Enter test score");
String q=JOptionPane.showInputDialog(
"Enter test score");
String w=JOptionPane.showInputDialog(
"Enter test score");
String b=JOptionPane.showInputDialog(
"Enter test score");
String z=JOptionPane.showInputDialog(
"Enter test score");
int y=Integer.parseInt(x);
int c=Integer.parseInt(q);
int d=Integer.parseInt(w);
int e=Integer.parseInt(b);
int f=Integer.parseInt(z);

calcAverage(y,c,d,e,f);

}
public static void calcAverage(int g, int h, int i, int l,int m){

int average=0;
average=(g+h+i+l+m)/5;
System.out.println(average);

}
public static void determineGrade(int g, int h, int i, int l,int m){

System.

System.

System.

System.