Calculating average from a letter grade - Programmers Heaven

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Calculating average from a letter grade

Posts: 2Member
Hello,
Recently I completed a home work assignemt that allows the user to enter 10 letter grades. The program computes and displays the average.
I am not satisfied with the code that I completed and was hoping to get some help with making improvements to the program.

Ideally this is how I would have liked the program to flow.
The user enters a series of 10 letter grades seperated by commas in the JOptionPane. String of letter grades transfered into an array of 10. Array of 10 letter grades then converted to its corresponding integer value and placed into a new array of 10 integers. Then determine the average of the integer array and displaying the class average via the JOptionPane.

Would someone on here be able to provide some advice on the attached/below code as to how I can improve it and include the user interacterbiliy I mentioned above.

Any help is greatly appreciated.
Many thanks,
Jonathan.

/*This program requires the user to enter 10 letter grades A,B,C and D
* the program then calculates the average of the grades and displays the results.
*/

import javax.swing.JOptionPane;

public class AverageWhile {

public static void main(String args[]) {
int counter, total;
float average;
// initialization phase
total = 0;
counter = 0;

// processing phase
for (counter = 1; counter <= 10; counter++) {

.showInputDialog("Enter Letter Grade for " + counter);
if (counter == 1) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 2) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 3) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 4) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 5) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 6) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 7) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 8) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 9) {

total = 4;
total = 3;
total = 2;
total = 1;

}

if (counter == 10) {

total = 4;
total = 3;
total = 2;
total = 1;

}

}
JOptionPane.showMessageDialog(null, "The Class Average " + average);
}

}