NOTE: Scheduled Maintenance for July 5th from 8PM-9PM EDT
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer connection crash dell drivers dvd email error excel firefox graphics hard drive hardware hijackthis install internet itunes keyboard laptop malware monitor motherboard network outlook outlook 2003 outlook 2007 problem registry cleaner registry cleaners router screen slow sound trojan ubuntu upgrade usb video virus vista windows windows 7 windows vista windows xp wireless word
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
another random java question

Tip: Click Here to Update All Your PC's Outdated Drivers
[ Sponsored Link ]

Closed Thread
 
Thread Tools
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
07-Apr-2007, 10: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,696 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
07-Apr-2007, 11:45 AM #2
totalaverage = ((totalaverage * (A-1)) + average) / A
RedWizard's Avatar
Member with 48 posts.
 
Join Date: Jan 2007
08-Apr-2007, 07:14 PM #3
i appreciate your assistance chicon.

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

=]
Thanks, RedWizard !
Closed Thread Bookmark and Share

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.


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


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 01:18 PM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Powered by Cermak Technologies, Inc.