There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu hard drive hardware hdmi internet laptop malware memory missing monitor motherboard network operating system printer problem ram registry router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
another random java question

Reply  
Thread Tools
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
07-Apr-2007, 11:56 AM #1
another random java question
Hello.

=]

I have been experimenting with for loops, and nested loops. In this application I enter and bowling scores for 2 players and get an average. In this example I have 2 players with 2 scores.

The issue I am having is keeping track of the accumulative average. As you can see I cannot discover an effective method of doing this

This application will calculate the average of 2 games for 2 bowling players, however I can not discover how to make it display the total average.

*/
import javax.swing.*;
public class Bowlers
{
public static void main(String[] args)
{
final int bowlerscores = 2; //define number of games as 3
final int threebowlers = 2; //establish the amount of bowlers as 3

int A,B;
double temptotalavg, totalaverage, score, total, average;
String s1;
//this line begins the first loop. the outter loop.
for (A = 1; A <= threebowlers; A++)
{
total = 0;
for (B = 1; B <= bowlerscores; B++)
{
s1 = JOptionPane.showInputDialog(
"Enter Score of Bowler:");
score = Double.parseDouble(s1);
total = total + score;
}
average = total / bowlerscores;
totalaverage = ??????
JOptionPane.showMessageDialog(null,
"The average for bowler # " + A + " is " + average,
"Mike's Nested Loop Average Bowl Application",
JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null,
"Therefore; as of yet the accumulative average is " + totalaverage,
"Mike's Nested Loop Average Bowl Application",
JOptionPane.INFORMATION_MESSAGE);

} // end of the outer for loop
System.exit(0);
}
}

If anyone could help me understand how to do this (without using any if statements or additional nests) i'd be much obliged..

Thanks again

-RedWizard
Chicon's Avatar
Computer Specs
Distinguished Member with 6,690 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
07-Apr-2007, 12:45 PM #2
totalaverage = ((totalaverage * (A-1)) + average) / A
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
08-Apr-2007, 08:14 PM #3
i appreciate your assistance chicon.

=]
Chicon's Avatar
Computer Specs
Distinguished Member with 6,690 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
09-Apr-2007, 05:18 AM #4
Quote:
Originally Posted by RedWizard
i appreciate your assistance chicon.

=]
Thanks, RedWizard !
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:44 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.