Java - arrays heeeelp!

Discussion in 'Scripting & Programming' started by Leehaa, Jul 15, 2010.

  1. Leehaa

    Leehaa Gigabyte Poster

    1,648
    21
    91
    Oh I am so stuck :(

    I have an assignment due in next week and I have been stuck on a 3 point (the assignments add up to 100 points and the next 80 points can only come after getting this part right) question for the last 3 days - for a total of about 6 hours.

    Can anyone help? I don't want to post the question as that would be cheating, but basically I need to write a constructor for objects of a new class. The argument that goes into it needs to be an array...

    Although I seemed to find the course exercises okay I just can't seem to get this darn thing to work - short of taking a hammer to my computer here...please can someone help/advise?

    Many Thanks.
     
    Certifications: MCP, MCDST, ITIL v3, MBCS, others...
    WIP: BSc IT & Computing, RHCE
  2. Leehaa

    Leehaa Gigabyte Poster

    1,648
    21
    91
    ...and yet again I have solved my own issue! :D

    It was so simple (would be for 3 marks)

    You basically had to declare a private instance variable first that would hold an array of type int

    ...and then in the constructor, take the value from the instance variable via this. using the main() method.

    I love posting here...somehow posting the question makes me think about the issue from a different angle as have to try and explain it in a way that people might understand...and then it all begins to make sense - lol!
     
    Last edited: Jul 15, 2010
    Certifications: MCP, MCDST, ITIL v3, MBCS, others...
    WIP: BSc IT & Computing, RHCE
  3. LukeP

    LukeP Gigabyte Poster

    1,194
    41
    90
    Try stackoverflow.com for programming related questions.
     
    WIP: Uhmm... not sure
  4. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    In Australia at the moment so hard for me to answer stuff quick

    Your explanation makes little sense, but glad you fixed it !

    Object member data can generally be accessed without using the this keyword unless you have overridden the name in another scope. In this case it's likely you named the constructor input parameter with the same name as the member variable.

    Class/Object member data should generally be private or protected to ensure encapsulation, therefore you would not be able to access it from a main() method of another class without calling an accessor method.
    If it was the main method, this method is also static and I expect the member data is most likely non static so then you would need an instance variable for the object and an accessor.

    Sounds like your issues are related to scopes, parameter passing and naming and not really array related at all !

    So what's the college course you're on ?
     
    Last edited: Jul 16, 2010
  5. Leehaa

    Leehaa Gigabyte Poster

    1,648
    21
    91
    Thanks for the answers. Yes I can see how it still wouldn't make much sense to anyone as I have left out a lot of detail. It is array related in that this. refers to a new array that I had declared above, but in the end the actual code needed didn't create an array itself - just passed it through (that's where I was getting confused). Am still going to use the this., as this is how it was taught in the relevant unit for the course and I've found that they like you to stick closely to the code in the course - only half way through though so no doubt it will get more advanced.

    I might post up the whole thing so you can understand what I mean once assignments have been handed in and marked. Will check what the rules for that type of thing with my tutor.

    The course is an object oriented programming with java with the OU. I am finding this latest assignment hard as had a busy time building up to it - had another course just finishing, which meant another assignment and an exam, then normal working week ontop. Hopefully once this is done it'll be a lot easier to get back on top of it and start talking sense again :biggrin
     
    Certifications: MCP, MCDST, ITIL v3, MBCS, others...
    WIP: BSc IT & Computing, RHCE
  6. Leehaa

    Leehaa Gigabyte Poster

    1,648
    21
    91
    Uhh??

    Somehow managed to get 94/100 for my assignment after all that panic :blink

    Obviously my coding is a lot better than I thought...and certainly much clearer than any explanation given above!!

    Will post up some code at some point soon, to show you what I was going on about .

    Thanks again for the help!
     
    Certifications: MCP, MCDST, ITIL v3, MBCS, others...
    WIP: BSc IT & Computing, RHCE

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.