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

Thread: Multiple Objects out of one.

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Multiple Objects out of one.

    I want to create a program and within that program I need to create a costumer object that ever time I go through a loop it creates a new costumer with all new specs. Basically my program right now is a little more advanced but I was just wondering how I would do this.
    My object is Person person = new Person();

    Then the part of my program that is linked to Person is another class named Person, but the rest of my program is in another class so I was just wondering how I would be able to go through and get new values for all the methods in Person each time the loop started over. If you would have any idea please I need help!


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Multiple Objects out of one.

    My object is Person person = new Person();
    That is a great way to store 1 single person instance. If you want to store more than one person object, you will need one of those for each person, or a variable type that can store multiple Person objects.

    how I would be able to go through and get new values for all the methods in Person each time the loop started over
    The same way you do it for one person. But it will have to be looped so you can do it more than once. A good time to do that I think is as you create each person (in a loop?) initialize each value for that person before going to the next person.

    ie:


    person1 = new person
    person1.name = fred
    person2.age = 40

    person2 = new person
    person2.name = joe
    person2.age = 0

    If you would have any idea please I need help!
    What have you tried? The idea of the assignment is to train your mind to come up with ideas!!

Similar Threads

  1. how to create multiple objects
    By dominco in forum What's Wrong With My Code?
    Replies: 8
    Last Post: November 6th, 2012, 08:12 AM
  2. [SOLVED] Persisting multiple objects of the same type to a file.
    By mjr in forum Object Oriented Programming
    Replies: 6
    Last Post: August 15th, 2012, 08:25 PM
  3. Replies: 1
    Last Post: April 26th, 2012, 11:06 AM
  4. Creating multiple objects with a for loop
    By JackCannon15 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 20th, 2011, 07:26 PM
  5. Replies: 6
    Last Post: May 15th, 2009, 06:06 PM