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>

[3651 byte] By [Maria81a] at [2007-11-27 2:38:27]
# 1
> outputArea.setText(results);Don't use the setText(...) method, use the append(...) method. Read the API to see how each method works.
camickra at 2007-7-12 2:59:37 > top of Java-index,Desktop,Core GUI APIs...
# 2

But wirh append(...) method the output is liket like this, but depends on the rounds:

Average Score: 56.00

Highest Score: 56.00

Lowest Score: 56.00

Rounds: 3.0

Player List

Date: Score:

3/5/07 56.00

Average Score: 66.00

Highest Score: 76.00

Lowest Score: 56.00

Rounds: 3.0

Player List

Date: Score:

3/11/07 76.00

Average Score: 73.00

Highest Score: 87.00

Lowest Score: 56.00

Rounds: 3.0

Player List

Date: Score:

3/18/07 87.00

and with setText(...) method the output is

Average Score: 73.00

Highest Score: 87.00

Lowest Score: 56.00

Rounds: 3.0

Player List

Date: Score:

3/18/07 87.00

which is fine but I want to appear all the three days not only the last one.

for example:

Average Score: 73.00

Highest Score: 87.00

Lowest Score: 56.00

Rounds: 3.0

Player List

Date: Score:

3/5/0756.00

3/11/07 76.00

3/18/07 87.00

Maria81a at 2007-7-12 2:59:37 > top of Java-index,Desktop,Core GUI APIs...
# 3
I need some help here please
Maria81a at 2007-7-12 2:59:37 > top of Java-index,Desktop,Core GUI APIs...
# 4

import javax.swing.JOptionPane;

import javax.swing.*;

class GolfScores

{

public static void main(String[] args)

{

String rnds,

srd ,

hScore,

lScore,

results,

getAvgScore,

date;

String listR = " ";//<-moved to here

intcounter;

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 = " ";//><moved

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);

}

}

}

Michael_Dunna at 2007-7-12 2:59:37 > top of Java-index,Desktop,Core GUI APIs...
# 5
I got it thanks
Maria81a at 2007-7-12 2:59:37 > top of Java-index,Desktop,Core GUI APIs...