Results 1 to 15 of 15
  1. #1
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default 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 06:09 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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:
    PLz help i`m seriously sick of this and i need to have it done by friday nite, tmw.
    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.

    I sincerely wish you the best of luck.
    Last edited by Fubarable; 02-06-2009 at 06:04 AM.

  3. #3
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default

    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!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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.

  5. #5
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default

    :S if youre saying print each value with different print statements i tried it doesnt work :( Its the same error.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cmizer View Post
    :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.

  7. #7
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default

    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.

  8. #8
    sfe23's Avatar
    sfe23 is offline Member
    Join Date
    Feb 2009
    Posts
    42
    Rep Power
    0

    Default

    Does it work now?

  9. #9
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default

    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...

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by cmizer View Post
    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.
    Surely you've looped through an array using a for loop, correct? If so, then just print all in the array this way. An alternative that works for 1-D arrays is to use the Arrays class:
    Java Code:
    System.out.println(java.util.Arrays.toString(myArray));

  11. #11
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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.

  12. #12
    cmizer is offline Member
    Join Date
    Dec 2008
    Posts
    19
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    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.
    the tracksearch and datearranger methods defintly work since it prints the result in the format datearranger makes it and the correct value from tracksearch.

    The l++ in the for statement doesnt change the value of l???b:confused:

  13. #13
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Quote Originally Posted by cmizer View Post
    The l++ in the for statement doesnt change the value of l???b:confused:
    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'...

    Java Code:
    for([b]int[/b] 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(l=0; ...
    ...and see what happens.
    Last edited by toadaly; 02-07-2009 at 07:46 AM. Reason: should have been an 'l' not an 'i'

  14. #14
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    dumb dee dumb...a deleted comment
    Last edited by toadaly; 02-07-2009 at 07:47 AM. Reason: superfluous

  15. #15
    halle_johnson is offline Member
    Join Date
    Feb 2009
    Posts
    1
    Rep Power
    0

    Default

    thanks toadaly, i was looking for the solution to the exact same problem, go UoL

Similar Threads

  1. [SOLVED] Reading a text file into an Array
    By DonCash in forum New To Java
    Replies: 13
    Last Post: 01-25-2011, 01:51 AM
  2. Reading from a file to make an array
    By Bomber_Will in forum New To Java
    Replies: 11
    Last Post: 01-21-2009, 09:19 AM
  3. Reading input file into an array
    By littlefire in forum New To Java
    Replies: 6
    Last Post: 10-19-2008, 12:51 AM
  4. Reading/Writing a File using byte array
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-16-2008, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •