. : News : . | . : Message of the Week : . |
You are currently viewing an archive of the Wilderness Guardians clan's IPB1 forums.
These forums were used by WG from 2008 to 2011, and now exist for historical and achival purposes only. For the clan's current forums, CLICK HERE. |
"You are a Wilderness Guardian. That northern wasteland; that land of blood, desolation and death is your dominion. Tonight we are going home." ~His Lordship |
---|---|---|
War Alert: OFF | Raid Alert: OFF | |
PM a WG Official![]() |
Posted: April 2, 2010 10:22 pm ![]() | |
![]() ![]() ![]() ![]() ![]() ![]() ![]() IRC Nickname: Gibble00 Group: Emeritus Posts: 775 Member No.: 100 Joined: January 3, 2008 Total Events Attended: 9 ![]() ![]() ![]() | Okay, I know some of yall can do Java programming. I'm dealing with arrays of People (class) that have several properties such as age (int), gender (char), and salary (int) and I need an instance method that adds a new item of type Person to the array of existing Persons (called 'people') and I'm having trouble adding them to this array. This is the code I need to edit: void addPerson (Person p){ // adds a person p to the end of the population instance variable // You complete this method } I'm having trouble doing this I think, I don't actually know if this is what's not working for me because my program doesn't have any errors but it won't run. I tried using ArrayList.add but that returns a void result and I need a result of type Person. -------------------- ![]() |
Posted: April 3, 2010 01:09 pm ![]() | |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() IRC Nickname: Tnuac Group: Emeritus Posts: 1806 Member No.: 51 Joined: December 30, 2007 Total Events Attended: 58 ![]() ![]() ![]() | Been a while since i did all that i'm afraid =s -------------------- ~Aetas: carpe diem quam minimum credula postero~ "Seize the day and place no trust in tomorrow" ![]() |
Posted: April 18, 2010 05:05 am ![]() | |
![]() ![]() ![]() ![]() ![]() IRC Nickname: Maxrobinsun Group: Emeritus Posts: 152 Member No.: 2095 Joined: October 16, 2009 Total Events Attended: 0 ![]() ![]() ![]() | I imagine that i'm probably too late to help but: import java.util.*; // Assume you have some people class already ArrayList<People> names; names = new ArrayList<People>(); Person p = new person(constructors here); names.add(p); ... Person[] result = new Person[names.size()]; names.toArray(result); It would be something like that I believe. However, if the array already exists then i'm afraid, you would have to find the nearest empty item in the array and add it there, or if the array is full, create a new one of size: Old + 1 and then copy it over and insert the new element. (Try Arrays.copyOf. EDIT: URL screws with tags: http://java.sun.com/javase/6/docs/api/java...28boolean\[],%20int%29, again not sure if it will work but looks like an option) Or at least it should look something like that, it's been a while since I did Java -------------------- ![]() Joined September '04 |