Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Help with class program!!! STUCK! Program not doing what I Want!!!

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Help with class program!!! STUCK! Program not doing what I Want!!!

    I am having problems in getting my program to return an array that contains counters to my main method.

    I have four methods: main, countBase, findMost, and computeAvg.

    For findMost and computeAvg method I checked to see if my programs were counting the amount of elements in array correctly by just individual return the count variable. They were. But when I put the count variable into array and then tried returning the array or when I messed with the array in the other method and asked to place the position in a number so I return the position as a number value, it only displayed weird junk.

    //in main
    //for findMost, return int value of position; for computeAvg return array with avg amount of count of element in the array
     
    int valueMost = findMost(arrayDNA1); //Sends the first array to the findMost method
    System.out.println("The position returned: " + valueMost);
     
    int[] valueAvg = findMost(arrayDNA1);
    for( int s = 0; s < valueAvg.length; s++)
    System.out.println(valueAvg);
     
    //in findMost, after the count of element that needs to be counted is done
    int[] valueCount = {countA, countT, countG, countC};
     
    //I look for the position for the largest value which was done correctly
    return largeIndex;
     
    //in computeAvg, for each count
    double avgA = (double)countA / arrayLength;
    .
    .
     
    double[] avgSeq = {avgA, avgT, avgG, avgC};
     
    return avgSeq;

    Please help I have no idea what I am doing wrong.
    Attached Files Attached Files
    Last edited by sketch_flygirl; April 1st, 2011 at 10:46 AM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    If you want help with code, you'll have to break your problem down into an SSCCE and post that instead. If you post more than a few lines of code, most people will ignore you. They aren't doing this to be mean or out of laziness- there are hundreds of posts here, and we simply don't have time to get to all of them.

    Break your problem down into smaller, specific steps.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    Made it short.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    Quote Originally Posted by sketch_flygirl View Post
    Made it short.
    That's a good start, but that's not an SSCCE. And you haven't actually told us what the problem is- what do you mean by "weird junk"? What did you expect to happen? What happened instead (be specific)?

    But we're really only going to be guessing until we get our hands on an SSCCE.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    The methods (other than main) are posed to count the occurrence of a char in the arrays I created. When i return the count of occurrence of a variable to the main, it reads the number. But when I work with placing the occurrence amount in the array in the other methods and then use a for and if loop to find the largest index and then return the largest number I get something displaying: [I@2df4eh5

    Is there some trick with the occurrence count to place in an array and to return the array with the number other then the display of [I@2de5..?

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    That looks like you're trying to print out an array, or an Object without a useful toString() method. But again, without seeing an SSCCE, I'm only guessing.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Nov 2009
    Posts
    14
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    the toString() method worked but all I am getting back is 0 from the arrays.

    Something wrong is happening between putting the occurrence count into the array and returning or using the array. I had already check individually if the occurrence count gave the right value so there nothing wrong with my counts. What do I do now?

  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,357
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: Help with class program!!! STUCK! Program not doing what I Want!!!

    Quote Originally Posted by sketch_flygirl View Post
    What do I do now?
    I asked for an SSCCE a few days ago. That seems like a good place to start. Narrowing your problem down to just a few lines is your best bet- and chances are, you'll figure out the problem yourself in the meantime. If you're going to be a programmer, get used to this process.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Two class program help
    By BuhRock in forum Object Oriented Programming
    Replies: 4
    Last Post: July 4th, 2012, 05:27 PM
  2. Program with transfer value from one class to another
    By Adam22 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 5th, 2011, 11:26 PM
  3. new program (lotto.class)
    By james137 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 3rd, 2009, 04:22 PM
  4. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM
  5. stuck on this program can any one help me
    By clive in forum AWT / Java Swing
    Replies: 2
    Last Post: March 10th, 2009, 05:54 PM