No code, since this looks like a homework assignment, but rather a suggestion...
In your code, you have values.add(...). Perhaps you need to check if a
JobHistory involving that user has already been inserted, and if so,
simply adjust the existing entry in the values[] by adding the
jobcount to that entry. This may involve removing and re-adding the
JobHistory record.
Wayne
On Wed, Sep 10, 2008 at 1:12 PM, amiller <[EMAIL PROTECTED]> wrote:
>
>
> I have an array of items that I need to merge together so that there
> is only
> one entry in the array per username (1st field) and the rest of the
> numbers
> are merged into the single entry.
>
> I end up with this: but I want to have this:
> ============================= ==============================
> usera 5 0 0 0 0 0 0 0 0 0 0 0 usera 5 2 0 0 0 0 0 0 0 0 0 0
> userb 5 0 0 0 0 0 0 0 0 0 0 0 userb 5 1 3 0 0 0 0 0 0 0 0 0
> userc 5 0 0 0 0 0 0 0 0 0 0 0 userc 5 4 3 0 0 0 0 0 0 0 0 0
> usera 0 2 0 0 0 0 0 0 0 0 0 0
> userb 0 1 0 0 0 0 0 0 0 0 0 0
> userc 0 4 0 0 0 0 0 0 0 0 0 0
> usera 0 0 0 0 0 0 0 0 0 0 0 0
> userb 0 0 3 0 0 0 0 0 0 0 0 0
> userc 0 0 3 0 0 0 0 0 0 0 0 0
>
>
>
> Here are the details. Maybe I should be building the array
> differently.
>
> I have an array of "JobHist" objects. The JobHist class has a name
> followed by 12 integers.
> public JobHistory(String name,
> int jan, int feb, int mar, int apr, int may,
> int jun,
> int jul, int aug, int sep, int oct, int nov,
> int dec) {
> .....
> }
>
> In my code I am doing something like:
>
> for (int n = 1; n < 12; n++) {
> // the month number is i
> // gets some sql data from a db that returns some names and a
> number
> while (rs.next()) }
> String username = rs.getString("username");
> int jobcount = rs.getInt("jobcount");
> switch (n) {
> case 1: values.add(new
> JobHistory(username,jobcount,0,0,0,0,0,0,0,0,0,0,0)); break;
> case 2: values.add(new JobHistory(username,
> 0,jobcount,0,0,0,0,0,0,0,0,0,0)); break;
> case 3: values.add(new JobHistory(username,
> 0,0,jobcount,0,0,0,0,0,0,0,0,0)); break;
> case 4: values.add(new JobHistory(username,
> 0,0,0,jobcount,0,0,0,0,0,0,0,0)); break;
> case 5: values.add(new JobHistory(username,
> 0,0,0,0,jobcount,0,0,0,0,0,0,0)); break;
> case 6: values.add(new JobHistory(username,
> 0,0,0,0,0,jobcount,0,0,0,0,0,0)); break;
> case 7: values.add(new JobHistory(username,
> 0,0,0,0,0,0,jobcount,0,0,0,0,0)); break;
> case 8: values.add(new JobHistory(username,
> 0,0,0,0,0,0,0,jobcount,0,0,0,0)); break;
> case 9: values.add(new JobHistory(username,
> 0,0,0,0,0,0,0,0,jobcount,0,0,0)); break;
> case 10: values.add(new JobHistory(username,
> 0,0,0,0,0,0,0,0,0,jobcount,0,0)); break;
> case 11: values.add(new JobHistory(username,
> 0,0,0,0,0,0,0,0,0,0,jobcount,0)); break;
> case 12: values.add(new JobHistory(username,
> 0,0,0,0,0,0,0,0,0,0,0,jobcount)); break;
> }
> }
> }
>
>
>
>
>
> On Sep 10, 9:31 pm, Joshua Marinacci <[EMAIL PROTECTED]> wrote:
>> what is your question?
>> On Sep 10, 2008, at 11:45 AM, amiller wrote:
>>
>>
>>
>> > Is this the right forum to ask a simple java question?
>>
>> > If not maybe someone could suggest a good Java forum and I'll be on my
>> > way.
>>
>> > Question is regarding merging arrays.
>>
>> > Alan
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---