confusing but interesting program
This program is hard to explain but I will try to do so with the best of my ability. First of all the program should ask the user how many events the user wants and then do the next part of the program the same amount as this number. The next part of the program should take user input which consists of something + a score the amount of times equal to the events. And then the program asks for a series of scores (such as 1 and 3 and whatever numbers) until the user inputs 0 and then stops the program.
Since this is confusing probably i will give you an example:
the user inputs:
4
(number of events)
then the user inputs:
bat 2
ball 3
hit 4
out 0
then the user inputs (these are the scores):
3
4
6
8
0
so the computer will output:
score 3: ball 1(this means that one ball was used which equals 3)
score 4: hit 1
score 6: ball 2(two balls were used to add to a score of 6)
score 8: hit 2
With this program I think I should use an array to seperate the different user inputs and a seperate array to seperate the scores...
Also, I got some of this done but I still have lots to go because this program is kind of confusing (took me a while to understand the program in english before i could start on it in java)
here is my code though... am i doing anything wrong so far?
import java.io.*;
import java.util.*;
publicclass TrivialApplication{
publicstaticvoid main(String args[])throws IOException{
int event_number = 1;
int index = 0;
String events ="ha";
int scores = 1;
int c = 0;
System.out.println("Type 0 to exit the program");
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: ");
// should this be a string array?
// i'm not sure because the program should read the item name
// and value of it's worth
String[] score_array =new String[event_number];
for (index = event_number; index > 0; index--){
events = kinput.readLine();
// i know this part doesn't work because it makes all the array values =
// to events but how do i make it so each value = seperate event?
for (c = 0; c < score_array.length; c++){
score_array[c] = events;
}
}
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());
}catch (NumberFormatException nfe){
System.out.print("\nNumbers only Please: ");
scores = Integer.parseInt(kinput.readLine());
}
}
while (scores == 0){
break;
}
}
}
}
Any help will be very appreciated ^_^
Thanks in advance!

