Confused on my Program

Ok so to start off, my program is giving me lots of trouble, I have been working on it for a while and this is what I have so far (I will explain what it does after I show you the program):

import java.io.*;

import java.util.*;

publicclass TrivialApplication{

publicstaticvoid main(String args[])throws IOException{

int game_number = 1;

int event_number = 1;

int index = 0;

String events ="";

int scores = 1;

int c = 0;

int score_i = 0;

int score_ii = 0;

int score_iii = 0;

String first ="";

int second = 0;

int sub = 0;

int [] score_array =newint[200];

String [] string_array =new String[200];

int [] int_array =newint[200];

int section = int_array.length;

BufferedReader kinput =

new BufferedReader (new InputStreamReader (System.in));

while (event_number > 0){

System.out.print("\nInput the number of events you want: ");

try{

event_number = Integer.parseInt(kinput.readLine());

}catch (NumberFormatException nfe){

System.out.print("\nThat is not a number, please restate: ");

event_number = Integer.parseInt(kinput.readLine());

}

while (event_number < 0){

System.out.print("\nPlease enter a positive number of events: "); event_number = Integer.parseInt(kinput.readLine());

}

if (event_number == 0){

System.out.println("Program has ended");

break;

}

System.out.print("\nInput the events and the scores created"); System.out.println(" because of them: ");

for (index = event_number; index > 0; index--){

events = kinput.readLine();

StringTokenizer myTokenizer =new StringTokenizer(events);

String [] new_string =new String[myTokenizer.countTokens()];

for (c = 0; myTokenizer.hasMoreTokens(); c++){

new_string[c] = myTokenizer.nextToken();

}

first = new_string[0];

try{

second = Integer.parseInt(new_string[1]);

if (score_ii < string_array.length){

string_array[score_ii] = first;

score_ii++;

}

if (score_iii < int_array.length){

int_array[score_iii] = second;

score_iii++;

}

}catch (NumberFormatException nfe){

System.out.print("\nError, please rewrite: ");

events = kinput.readLine();

myTokenizer =new StringTokenizer(events);

new_string =new String[myTokenizer.countTokens()];

for (c = 0; myTokenizer.hasMoreTokens(); c++){

new_string[c] = myTokenizer.nextToken();

}

first = new_string[0];

second = Integer.parseInt(new_string[1]);

if (score_ii < string_array.length){

string_array[score_ii] = first;

score_ii++;

}

if (score_iii < int_array.length){

int_array[score_iii] = second;

score_iii++;

}

}

if (second > 0){

}else{

System.out.print("\nError, please rewrite: ");

events = kinput.readLine();

myTokenizer =new StringTokenizer(events);

new_string =new String[myTokenizer.countTokens()];

for (c = 0; myTokenizer.hasMoreTokens(); c++){

new_string[c] = myTokenizer.nextToken();

}

first = new_string[0];

second = Integer.parseInt(new_string[1]);

if (score_ii < string_array.length){

string_array[score_ii] = first;

score_ii++;

}

if (score_iii < int_array.length){

int_array[score_iii] = second;

score_iii++;

}

}

}

score_ii = 0;

score_iii = 0;

System.out.print("\nInput various scores that the program"); System.out.println(" will test your game on:");

while (scores != 0){

try{

scores = Integer.parseInt(kinput.readLine());

while (scores < 0){

System.out.print("Only positive numbers please: ");

scores = Integer.parseInt(kinput.readLine());

}

if (score_i < score_array.length){

score_array[score_i] = scores;

score_i++;

}

}catch (NumberFormatException nfe){

System.out.print("\nNumbers only Please: ");

scores = Integer.parseInt(kinput.readLine());

while (scores < 0){

System.out.print("Only positive numbers please: ");

scores = Integer.parseInt(kinput.readLine());

}

if (score_i < score_array.length){

score_array[score_i] = scores;

score_i++;

}

}

}

score_i = 0;

for (c = 0; c < score_array.length; c++){

if (score_array[c] != 0){

System.out.print("\nGame #" + game_number +", score "); System.out.println(score_array[c] +":\n");

while (section > 0){

section--;

if ((int_array[section] > 0) && (int_array[section] <= score_array[c])){

System.out.println(string_array[section] +": " + int_array[section]);

}

}

section = int_array.length;

}

}

// resets values so they can be used again in the while loop

game_number++;

scores = 1;

section = int_array.length;

sub = 0;

}

}

}

Ok... so this is what my program does so far:

It asks the user for a number of events, takes the input and uses that to tell how many events the user should input. After that, it takes events from the user, these events are supposed to be a word and then a number such as Goal 4. The program breaks these inputs into tokens and places them in seperate arrays. One array being strings (which the Goal would fit into) and the other being integers (where the 4 goes). Then the program takes a list of scores (integers) from the user until they input 0. The program saves these integers and places them in an integer array.

Now that all the saving is done, the program outputs the current game number (each different run of the program is a new game) and then ouuputs the first score the user inputted. The program then goes backwards through the array of integers that the user inputted for the events. If these values are lower than that of the score, they will be ouputted. The program continues to do this until this is done for all the scores.

Now that I have explained what I got it to do, here are the problems. Instead of the program outputting all of the events that create a lower value than that of the score, it should just output those that add together to create the sum. This is done in a way to say how many times the event is called upon. Since this is confusing I will give an example.

The events are these:

throw 2

catch 1

eat 5

scores are these:

5

3

1

Output would be:

Game # 1 Score 5:

eat: 1 (since the action eat is equal to 5 and only one of these events occur)

Game # 1 score 3:

throw:1

catch:1

Game # 1 score 1:

catch: 1

Now I tried doing this by creating an integer value factor which would be equal to the score value (of the array at the moment) minus the closest array value. This is like 3 (being the score) - 2 (being the closest number in the array lower than 3) = 1. I don't know if this would be any use in this program however, but I think it might be because it tells us how much is left over to subtract from, I just don't know where to put it.

Also, this program has one last exception I can't seem to fix. It does an exception when the user inputs something for an event that is less than 2 tokens, this is because the program requires 2 tokens to work. Is there any exception handling thing to fix this.

Sorry if this seems like a wall of crazy text but I really do hope I can get a bit of help on this since i've been working on it for a while and can't seem to get any further.

Thanks all!

[12341 byte] By [RAWR-itsanONIONa] at [2007-11-27 7:06:54]
# 1
Best advice I can offer at this point isMETHODS!METHODS!METHODS!METHODS!
floundera at 2007-7-12 18:58:12 > top of Java-index,Java Essentials,Java Programming...