Results 1 to 3 of 3
  1. #1
    rachel_17 is offline Member
    Join Date
    Jul 2010
    Posts
    1
    Rep Power
    0

    Default arraylist handling

    here's what my code should do:

    bundle01|1.0|2.0|3.0|4.0|remarks
    bundle02|1.0|2.0|3.0|4.0|remarks
    bundle03|1.0|2.0|3.0|4.0|remarks
    bundle02|1.0|2.0|3.0|4.0|remarks

    my array should only include no duplicate bundle.
    so i want to exclude the one bundle02 in the list and its 2nd pipe delimited value ( 1.0 ) will be added to the 2nd pipe delimited.

    output below:

    duplicate remove form the list, 2nd pipe delimited sums up to 2.0

    bundle01|1.0|2.0|3.0|4.0|remarks
    bundle02|2.0|2.0|3.0|4.0|remarks
    bundle03|1.0|2.0|3.0|4.0|remarks

    try some code lines i only able to remove duplicate lines but unable to add the sum of the 2nd pipe delimited value.

    appreciate much your response
    thank you all

    Edit/Delete Message

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,655
    Blog Entries
    7
    Rep Power
    21

    Default

    You should build a class Bundle:

    Java Code:
    public class Bundle {
       private String name;
       private double[] pipes= double[4];
       private String remarks;
    
       // constructor(s) go here ...
    }
    That class should have a bit of algebra defined in it, i.e. it should implement an equals( ... ) method (and the hashCode() method that comes with it) so that you can put a Bundle in a HashMap. If you want a bit of ordering in your Bundles your class should also implement the Comparable<Bundle> interface.
    If a Bundle already occurs in your map the Bundle should be updated (the first pipe length? should be adjusted); it can be done with a simple method like this:

    Java Code:
    public void update(Bundle that) {
       this.pipes[0]+= that.pipes[0];
    }
    You fill in the details ...

    kind regards,

    Jos

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,091
    Rep Power
    20

    Default

    Wouldn't a HashSet make more sense, since there should only be one of each thing? Barring the ordering, of course, but you can always get round that.

Similar Threads

  1. Event Handling
    By zzpprk in forum AWT / Swing
    Replies: 2
    Last Post: 11-12-2009, 09:30 PM
  2. Replies: 2
    Last Post: 04-21-2008, 11:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •