program problem
My program is running fine, every time the user input the date and the score it will appear the average, high score, low score, the round and with a different title the date and the score, but every time the user input another date and sc ore needs display again the average, high score, low score, the round and with a different title all the dates and the scores.
But it is not doing it; it is only carrying the information from the last date and score and is suppose to carry all of them.
The average, high score, low score are fine.
This is my code:
import javax.swing.JOptionPane;
import javax.swing.*;
publicclass GolfScores
{
publicstaticvoid main(String[] args)
{
String rnds,
srd ,
hScore,
lScore,
results,
getAvgScore,
date;
int counter;
double rounds,
scores,
sumScores=0.0,
highestScore=0.0,
lowestScore=0.0,
avgScore=0.0;
JTextArea outputArea =new JTextArea(8, 30);
JScrollPane scroller =new JScrollPane(outputArea);
rnds = JOptionPane.showInputDialog("Welcome to the Golf Scores System!\n"
+"Enter the number of rounds: ");
rounds = Double.parseDouble(rnds);
for(counter = 1; counter <= rounds; counter++)
{
date= JOptionPane.showInputDialog("Enter player date " + counter
+" score: ");
srd = JOptionPane.showInputDialog("Enter the score: ");
scores = Double.parseDouble(srd);
sumScores = sumScores + scores;
avgScore = sumScores/counter;
getAvgScore = String.format("Average Score: %.2f\n", avgScore);
if(scores>highestScore)
{
highestScore = scores;
}
hScore = String.format("Highest Score: %.2f\n", highestScore);
if(counter==1)
{
lowestScore = highestScore;
}
if(scores<lowestScore)
{
lowestScore = scores;
}
lScore = String.format("Lowest Score: %.2f\n", lowestScore);
String listR =" ";
listR = listR + String.format("%s %.2f\n\n", date, scores);
results = getAvgScore + hScore + lScore +"Rounds: " + rounds +"\n\n" +
"Player List\n" +" Date:" +"Score:\n" + listR;
outputArea.setText(results);
JOptionPane.showMessageDialog(null, scroller,"Report of Golf Score.",
JOptionPane.PLAIN_MESSAGE);
}
}
}
Thanks>

