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 5 of 5

Thread: Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

    Could Someone please help me two simple examples of how to do the following ?
    Keep in mind the test the Arraytest.class has to be separate from the Array Class.

    (Below is my fail attempts )

    Question1: ///What I need to happen isArrayFull() : returns whether the array holding the vale is full or not.
    the array does get full when it reaches 5.
    ----------------------------------------------------------------------------
    Class: Array.Java
    public boolean isArrayFull() {
    if (array.length < mMaxArray) {
    /// Dont know how to call the array length to be checked
    return false;
    } else {
    return true;
    }
    }


    //// Question 2 /// getMostRecentAmount(): returns the amount of the most recent array ( so last bit of the array.). If there haven't been any information added to the array is to return 0.

    public int getMostRecentAmount() {
    // if(array.length > 0){ /// if the array length is greater then zero do this
    // /// method to search the array last bit
    // return ; /// returns the most recent part of the array
    // }
    // else {
    // return 0;
    // }

    }

    -----------------------------------------------------------------------------
    /// Having Trouble calling the array from the other class to test it

    Class: TestArray.java

    Array array1;
    Array array2;

    Array1 = new array1("ArrayName1", 78732983, 73);
    Array1.finish();
    System.out.println(array1.toString());

    array2 = new array2 ("002 ArrayName2", 43232, 432);
    array2.makeBet("Steven", 5300, 4);
    array2.makeBet("James", 5600, 27);
    array2.makeBet("Steven", 7000, 44);
    array2.makeBet("James", 7500, 134);
    array2.makeBet("Steven", 8700, 231);
    array2.finish();
    System.out.println(array2.toString());
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,859
    My Mood
    Mellow
    Thanks
    178
    Thanked 631 Times in 618 Posts

    Default Re: Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

    Please read the Announcement topic at the top of the sub-Forum to learn how to post your code in code tags and other great info for new forum users.

    Per Java's naming convention, class names begin with capital letters and variable and method names begin with lowercase letters. Please respect Java's naming convention.

    I gather you're creating your own Array class which may or may not be an extension of the existing Arrays class. Is that right? If so, I suggest you pick a name for your class that doesn't conflict with existing core Java classes.

    What does the finish() method do? In fact, you might want to post your entire Array class (renamed, if possible) so that we can see what you've done and plan to do.

    From the snippets you've shown (which may not be enough), I think all you need to do is maintain a counter in an Array instance variable that keeps track of the number of elements that have been added to your Array objects. ArrayList already does this for you, but ArrayLists don't get "full," though you could pretend they do.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

    Please read the Announcement topic at the top of the sub-Forum to learn how to post your code in code tags and other great info for new forum users. - Ok I will do this , Wasn't to sure thought be fine if i posted it the way I did.

    Per Java's naming convention, class names begin with capital letters and variable and method names begin with lower-case letters. Please respect Java's naming convention. - Yeah I respect them I was just writing up an example next time ill name things better or fix it up if you want.

    I gather you're creating your own Array class which may or may not be an extension of the existing Arrays class. Is that right? If so, I suggest you pick a name for your class that doesn't conflict with existing core Java classes. - The array is already existing in the test class yes. I only called it array because I was giving an example of what i wanted to do. (totally agree what your saying.)


    What does the finish() method do? In fact, you might want to post your entire Array class (renamed, if possible) so that we can see what you've done and plan to do.- The finish method just states where the array has finished. If you think its 100% necessary ill re write it and put a different situation that does the same outcome ?

    From the snippets you've shown (which may not be enough), I think all you need to do is maintain a counter in an Array instance variable that keeps track of the number of elements that have been added to your Array objects. ArrayList already does this for you, but ArrayLists don't get "full," though you could pretend they do. - (I was thinking about adding a counter but was unsure how to do so with the array structure I was using sorry i'm inexperienced. (I dont want to edit the way I structured the array because its required to be set out like that. ) )ArrayList adds the counter thanks. Didn't know that. (ArrayList already does this for you, but ArrayLists don't get "full," though you could pretend they do.( now you got me thinking ! RAGE !) sorry for the confusion I LEFT this out the array does get full when it reaches 5.

    Thank you so much for your help.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,859
    My Mood
    Mellow
    Thanks
    178
    Thanked 631 Times in 618 Posts

    Default Re: Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

    If I understand your description of the finish() method, it would be unnecessary if you had a counter.

    I dont understand your statement, "I dont want to edit the way I structured the array because its required to be set out like that." If that's the case, and what you have either can't be changed or you don't want to change it, then why have you asked for help to make it better or different. That doesn't make sense, and it appears we'd be wasting our time offering suggestions.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Array Help Needed- Testing if ArrayIsFull & Displaying Most Recently added Array data

    If I understand your description of the finish() method, it would be unnecessary if you had a counter. - I suppose I could change remove the finish() method then and use a index counter.
    Demonstration be great.

    I don't want to edit the way I structured the array because its required to be set out like that. - I only said that because the test classes were provided to me like that.

    Then why have you asked for help to make it better or different. That doesn't make sense, and it appears we'd be wasting our time offering suggestions. - I'm asking for help with the question I stated. Clearly from what your saying is I really do need to edit the TestArray.java class. (It was more I much preferred not to edit my test class that was all.)

    Thanks for making that clear to me.

Similar Threads

  1. Searching and displaying results in a multi-dimensional array.
    By wfalcon2012 in forum Collections and Generics
    Replies: 2
    Last Post: February 18th, 2012, 07:06 PM
  2. Displaying Array Not Working.
    By tleblanc in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 3rd, 2011, 10:25 AM
  3. Testing values in an array.
    By bholzer in forum Loops & Control Statements
    Replies: 7
    Last Post: September 28th, 2011, 05:18 PM
  4. [SOLVED] Accessing && Editing properties of objects in an array. Plus a few more questions.
    By CameronFaust in forum Collections and Generics
    Replies: 31
    Last Post: August 10th, 2011, 07:35 PM
  5. [SOLVED] theory behind testing each element of an array.
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: February 5th, 2010, 08:04 AM