Results 1 to 15 of 15
Thread: Array not reading. Plz help
- 02-06-2009, 04:56 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
Array not reading. Plz help
Hey guys after many tiresome days of doing this on my own im pretty much finished all i need to do is have the summary print all the dates and names and where the win occured for each horse entered.
Problem it only prints the last date and trackid the user inputs :( If the horse won 2 times its supposed to print when and where it won each time. Instead it prints the last time it won n where twice.
PLz help i`m seriously sick of this , NOT MEANING TO RUSH ANYONE. I greatly appreciate any help given here. Thank you all in advance.
Below are the parts involved with the problem im gettin so im pretty sure that the problem is in here. :S
Java Code:int i,j,m,l; int pos=0; int[] nums=new int[3]; String[] name=new String[3]; int[] wdate1=new int[9]; int[] wtrack1=new int[9]; String mnt[]= {" ","January","February","March","April","May","June","July","August","September","October","November","December"}; String day=" "; int wyear,wmonth,wday,dm; System.out.println("Please enter the number of races " +horsename + " has won: "); win=sc.nextInt(); do { for(int j=0;j<win;j++) { winc++; System.out.println("Please enter the date of win "+winc+"(yyyymmdd): "); wdate1[j]=sc.nextInt(); System.out.println("Please enter the track of win " +winc+": "); wtrack1[j]=sc.nextInt(); }while (winc<win); System.out.println("Would you like to enter more data? Y or N"); char ans=(char)System.in.read(); if(ans=='y') { loop=true; } else if(ans=='n') { datearranger(); tracksearch(); summary(); } public void datearranger() //complete { for(m=0; m<win; m++) { wyear=wdate1[j]/10000; dm=wdate1[j]%10000; wmonth=dm/100; wday=dm%100; if(wday==01 || wday==21 || wday==31) day="st"; else if(wday==02 || wday==22) day="nd"; else if(wday==03 || wday==23) day="rd"; else day="th"; } public void tracksearch() { boolean found=false; for(int k=0;((k<wtrack1.length)&&(!found));k++) { if(wtrack1[j]==nums[i]) { found=true; pos=i; //System.out.println("at the" + name[pos]); } } } public void summary() { for(int l=0; l<win; l++) { System.out.println("Summary:"); System.out.println(horsename+" has won "+win+" races."); System.out.println("On the " +wday+day+" "+mnt[wmonth]+" "+wyear+" at the "+name[pos]); datearranger(); tracksearch(); //System.exit(0); } }Last edited by cmizer; 02-06-2009 at 05:09 AM.
-
I hate to tell you that you're posting way too much code, and that this will diminish your chances of getting help, as many will just not want to bother going through it all. If you are serious about getting help, I recommend that you isolate the code that is causing the problem, place it in a small compilable and runnable program and post it.
Also, this:isn't going to help. Please remember that we are volunteers and don't like to be put under pressure. Remember that this is your problem not ours.PLz help i`m seriously sick of this and i need to have it done by friday nite, tmw.
I sincerely wish you the best of luck.Last edited by Fubarable; 02-06-2009 at 05:04 AM.
- 02-06-2009, 05:04 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
thank you but im not exactly sure wat is causing the prob i`ll see wat i can do. I DONT MEAN TO PRESSURE YOU GUYS!!SORRY!
-
Then it's time to do some debugging. Sprinkle your code generously with many println statements and find the source of the problem. Again, much luck.
- 02-06-2009, 05:21 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
:S if youre saying print each value with different print statements i tried it doesnt work :( Its the same error.
-
No, I'm saying to use println statements to help debug your code. You use them throughout the program each one printing out information that describes the current state of your program at that time and on that line. Either do that or use a debugger to see what your code is doing at critical times.
- 02-06-2009, 05:28 AM #7
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
the way the actual prog works is that it does that.
The problem with this is that the final print statement which is in a loop only prints the last element of the array which holds wat its supposed to print.
I`m really new to this and had to teach myself arrays. Do you know how to use the print statements to show me everything in the array? I guess from there i can know the error.
- 02-06-2009, 06:09 AM #8
Does it work now?
- 02-06-2009, 06:14 AM #9
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
nope same error i tries a bunch of stuff and it gave me no reults at all so i switched back to the original code. Messed with it some more and nothing...
-
- 02-06-2009, 07:27 AM #11
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
In your 'summary method, I don't see anything that changes within the loop. Each iteration of 'l' has the same value of 'horsename' and the same value for 'win'. The calls to 'dateArranger' and 'trackSearch' have no affect on what is printed in the loop as far as I can see with a quick glance.
- 02-06-2009, 03:02 PM #12
Member
- Join Date
- Dec 2008
- Posts
- 19
- Rep Power
- 0
- 02-07-2009, 06:45 AM #13
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
The l++ does change the value of 'l', but you aren't using that value to do anything, which is why it just prints the same thing over and over. The 'l' in the loop is a different 'l' than the one you declared at the class level.
This 'l'...
is a local variable, not the global one. I didn't notice the class level declaration of 'l' the first time I glanced at this. Change your for loop in the summary method to ...Java Code:for([b]int[/b] l;...
...and see what happens.Java Code:for(l=0; ...
Last edited by toadaly; 02-07-2009 at 06:46 AM. Reason: should have been an 'l' not an 'i'
- 02-07-2009, 06:46 AM #14
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
dumb dee dumb...a deleted comment
Last edited by toadaly; 02-07-2009 at 06:47 AM. Reason: superfluous
- 02-12-2009, 12:02 AM #15
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
[SOLVED] Reading a text file into an Array
By DonCash in forum New To JavaReplies: 13Last Post: 01-25-2011, 12:51 AM -
Reading from a file to make an array
By Bomber_Will in forum New To JavaReplies: 11Last Post: 01-21-2009, 08:19 AM -
Reading input file into an array
By littlefire in forum New To JavaReplies: 6Last Post: 10-18-2008, 11:51 PM -
Reading/Writing a File using byte array
By Java Tip in forum Java TipReplies: 0Last Post: 01-16-2008, 10:41 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks