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

Thread: New to Java: Arry of Objects

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool New to Java: Arry of Objects

    Post removed
    Last edited by Jack Hammered; January 4th, 2012 at 08:25 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New to Java: Arry of Objects

    trying to import a sinlge object, MM, imto an array of these objects
    You can use an assignment statement to put an object into an array. Given an array: anArray, anObject and an index: theIndex
    anArray[theIndex] = anObject; // put anObject into the array at theIndex slot

    Can you explain your problem? Do you get errors? If so please post them here.
    Does the code execute?
    If it does not do what you want it to do, please explain. What do you want it to do that is different from what it does.

  3. #3
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to Java: Arry of Objects

    Post removed
    Last edited by Jack Hammered; January 4th, 2012 at 08:24 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New to Java: Arry of Objects

    how to pass on the object from its class (movie) to the object array (movieList)
    How does your posted code relate to your question?
    Your posted example does not have an array: movieList or a class movie. What is the name of the object that you want to pass.

    movie() appears to be a method. The ending ()s says it is a method.

    The only array name I see is MML which is defined in the MovieList class and used in method: importRecord(). Are these two different arrays in two different classes with the same name?
    Note: Standard class names begin with uppercase.

    You need to use correct terminology when talking about your code.

  5. #5
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to Java: Arry of Objects

    Thank you for your help: I guess me being new to Java I wouldn't know what I was doing. I thought I created an object of (movie) and I wanted to import that into a position within the movieList (MML) array. Sorry to have bothered you.

    {
      // --- Create an object ---
      MyObject obj = new MyObject();
     
      // --- Use the object ---
      obj.printMyValues();
    }

    // --- Creating the object ---
    movie MM = new movie();
     
    // --- Using the object
                MM.movie_title = movie_title;
                MM.movie_released = movie_released;

    AFAIK
    Last edited by Jack Hammered; January 4th, 2012 at 08:43 PM. Reason: IDK

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New to Java: Arry of Objects

    It's important to get the vocabulary right and to use the correct spellings and names when describing a problem. Not many of us are mind readers. There are too many different ways to go wrong that a partial incorrect example makes it very hard to understand what you are trying to do.

  7. #7
    Junior Member
    Join Date
    Jan 2012
    Posts
    7
    My Mood
    Depressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New to Java: Arry of Objects

    Apparently there are too many problems with my code or with what I have said. I do not understand the terms or vocabulary very well: Neither I nor my code can express what I intended.

    Movie - Java file
    Movie - Class
    //details of movie

    Menu - Java file
    Menu - Method
    //create movie object of movie class (MM)
    //assign values to movie object (MM)

    MovieList - Java file
    MovieList - Class
    //point to object (MM)
    //insert (MM) into array of said objects (MML)

    I appreciate you having a look and telling me that I haven't done what I intended to do nor what I have done is correct. It seems I have not only wasted your time but mine as well.
    Last edited by Jack Hammered; January 4th, 2012 at 09:55 PM.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: New to Java: Arry of Objects

    //insert (MM) into array of said objects (MML)
    Is this what you are asking about:
    MML[indexOfNextEmptySlot] = MM; // insert/add object MM to the array MML
    indexOfNextEmptySlot++; // move index to next slot

  9. #9
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: New to Java: Arry of Objects

    Please do not remove your posts like this. You have rendered this thread useless. Next time will be an infraction.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  10. The Following User Says Thank You to JavaPF For This Useful Post:

    newbie (January 5th, 2012)

Similar Threads

  1. Java TV Board Game/Grid + Moving objects
    By Massaslayer in forum Java Theory & Questions
    Replies: 6
    Last Post: December 13th, 2011, 08:03 AM
  2. how to merge java objects with effective dates
    By java4ulok in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 10th, 2011, 01:24 PM
  3. java question on objects
    By joe98 in forum Threads
    Replies: 2
    Last Post: April 12th, 2011, 03:54 PM
  4. New to Objects...
    By Java Neil in forum What's Wrong With My Code?
    Replies: 17
    Last Post: March 24th, 2011, 07:00 AM
  5. Java Sockets, Bytes / Objects
    By AdamD in forum Java Networking
    Replies: 1
    Last Post: January 31st, 2011, 03:25 PM