reset password
Author Message
skim144
Posts: 63
Posted 20:48 Apr 23, 2014 |

How do i make more than 1 phone number for a person?

I'm thinking ArrayList<PhoneNumber>, but it's been a lot of repair for my code. I wonder if this is correct..

MariahM
Posts: 35
Posted 20:51 Apr 23, 2014 |

That is correct. Where are you creating your Array List for Phone number objects?

skim144
Posts: 63
Posted 20:59 Apr 23, 2014 |

I'm doing it in main. All of my data are in main. And its very MESSY!

Last edited by skim144 at 21:00 Apr 23, 2014.
MariahM
Posts: 35
Posted 21:25 Apr 23, 2014 |

Its going to have a lot of information. yes. 

 

Does you Person constructor take in an ArrayList of PhoneNumber objects?

HeroVega
Posts: 8
Posted 21:26 Apr 23, 2014 |

It shouldn't be too messy. Try doing it for only 1 or 2 people objects, since your hardcoded data is only to test your classes. You basically create more phone objects and add them to the array list.

For example, Bob has 2 phone numbers.

You would create two phone number objects

bobPhone1 = blah blah;

bobPhone2 = even more blah;

Then you would add those two to an array list, as you originally thought

Whatever your phone arraylist is.add(bobPhone1);

Whatever your phone arraylist is.add(bobPhone2);

Finally you would make the Bob object - Person Bob, blah blah

and pass the array list into it.

 

You should only have to add a couple more lines to some classes so they can print either the single number object or the array list of number objects.

Hope that helps remove some of the mess.

skim144
Posts: 63
Posted 21:27 Apr 23, 2014 |

Yeah I'm working on it and I have to fix a lot of my code. Thanks guys!

Last edited by skim144 at 21:28 Apr 23, 2014.