|
-
March 25th, 2012, 12:44 PM
#1
Average grade program
i need help with my array ad parameters i don't know how to fix this program.
This is a program that allows a user to enter class grades into an array of floats. The app will prompt for the total number of grades to be entered, then call a method to average the grades, and display the grades and the resulting average.
This is my code
import javax.swing.JOptionPane;
public class Average {
public static void main(String[]args)
{
String input,amount;
double data[], gradetotal1;
double sum=0,average;
System.out.println("\tAverage Program");
amount=JOptionPane.showInputDialog("Input Number of grades to enter");
gradetotal1=Double.parseDouble(amount);
data[]=gradetotal1;
for (int i=0;i<data.length;i++){
input=JOptionPane.showInputDialog("Enter grades");
data[i]=Double.parseDouble(input);
}
for(int i=0;i<data.length;i++){
sum+=data[i];
average=sum/data.length;
JOptionPane.showMessageDialog(null, "The total is:"+sum+"The Average is:"+average, JOptionPane.INFORMATION_MESSAGE);
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|