Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 136,250 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,224 people online right now. Registration is fast and FREE... Join Now!




nested loops help.....

 
Reply to this topicStart new topic

nested loops help.....

confuzzeld
14 Oct, 2008 - 07:26 AM
Post #1

New D.I.C Head
*

Joined: 30 Sep, 2008
Posts: 4

java
public class bowling
{
// The following is an instance of Scanner which you will use to
// read from the user.
public Scanner file = new Scanner ("3 " +
"10 0 120 150 170 " +
"11 1 200 250 220 " +
"12 0 200 200 200 " +
"13 1 150 120 130 " +
"-99 ");

public static void main (String[] args)
{
bowling program = new bowling ();

program.run ();
}

public void run ()
{
int numOfGames;
int id;
int counter;
int gender;
int scores;
int averageScore;
int handicap;
final int difference = 200;
final double mHandicap = 0.8;
final double fHandicap = 0.75;

numOfGames = file.nextInt();
counter = 0;

while(counter < numOfGames)
{
id = file.nextInt();

while (id > 0)
{
gender = file.nextInt();
if(gender == 0)
{
scores = file.nextInt();
averageScore = scores / numOfGames;
handicap = (difference - averageScore) * mHandicap;
if(handicap < 0)
{
System.out.println ("Handicap is false");
}
}
else if(gender == 1)
{
scores = file.nextInt();
averageScore = score / numOfGames;
handicap = (difference - averageScore) * fHandicap;
if(handicap < 0)
{
System.out.println ("Handicap is false");
}
}
if (score > highestScore)
{
highestScore = score;
highestID = id;
}
id = file.nextInt();

if (id < 0)
{
System.Out.println("The highest score is " + highestID + " with a score of " + highestScore);
}

}

System.out.println("Bowler's ID\t\tAverage Score\t\tBest Game\t\tHandicap");
System.out.println(id + "\t\t" + averageScore + "\t\t" + bestGame + "\t\t" + handicap);
System.out.println(highestScoringM);
System.out.println(highestScoringF);
}
counter++;
}
}



hi. i need some help with this. all im trying to do is what i think is a selection sort (calculate averageScore, calculate a handicap, print the id, average score, best game(where they scored the best) and there handicap and sort through to get the best female and male score). im having troubles in 3 parts, won't compile because of possible loss of precision on handicap = (difference - averageScore) * mHandicap;, not sure how to sort through to find the best scoring female and male, and how to find the players best game. Ive made several attempts at this part of the code and it just looks like complete garbage. Any help would be greatly aprreciated.

- one confused kid-
*Edited by pbl to add the code=java tag. That "might" shows the identation problem

This post has been edited by pbl: 14 Oct, 2008 - 08:47 PM
User is offlineProfile CardPM
+Quote Post

Gloin
RE: Nested Loops Help.....
14 Oct, 2008 - 01:09 PM
Post #2

On MeD.i.Cation
Group Icon

Joined: 4 Aug, 2008
Posts: 723



Thanked: 47 times
My Contributions
You never update the counter variable because it's outside of the while-loop that uses counter in the condition.
It doesn't look like this because your indentation is poor.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 04:12AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month