Results 1 to 3 of 3
  1. #1
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    Default Help with Arrays and Jexcelapi

    I've finally got Jexcelapi working and am able to read cell values and print them out. Now I want to use the data I read in from the spreadsheet. I'm able to read the data, perform math operations, and print it out again... but only one cell at a time.

    I'm building a simple card game. I want to read the data in from excel and temporarily modify the values without writing back to Excel. For example, here is a sample of the data from the spreadsheet I am reading...

    Unit_______Attack___Health
    Infantry01____2________6
    Infantry02____2________6
    Infantry03____2________6
    Cavalry01_____4________8
    Cavalry02_____4________8
    Archer01______3________3


    I want to read this data from the spreadsheet into an array of objects, then be able to change individual elements of the array. For example, subtract Health off a Unit that gets attacked.

    I have been messing around with arrays and am having trouble understanding how to do this.

    I just started using Java a couple weeks ago and have done a lot of reading. I finally learned how to read/write from a spreadsheet, but I don't want to create a temporary spreadsheet because I really don't build my program this way and would like to learn how to do it with arrays.

    Any help would be appreciated.

    Thanks in advance!

    PS - I would like to be able to read this data into a single array of 6 rows and 3 columns instead of making 3 arrays.
    Last edited by Psyclone; 01-30-2010 at 05:42 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Psyclone View Post
    PS - I would like to be able to read this data into a single array of 6 rows and 3 columns instead of making 3 arrays.
    And this is the crux of the issue. You should create a class composed of at least 3 fields:
    Java Code:
    String unit;
    int attack;
    int health;
    Give your class setters and getter methods as well as perhaps increment methods (i.e., increment(health h)).

    Then create and use an Array of objects of this class. Better still, create an ArrayList of these objects. Or if you are going to be accessing these objects based on the unit name, you could even use a HashMap<String, MyObject> type of collection (check the tutorials on this one!).

    Much luck!

  3. #3
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    Default

    Thanks Fubarable, I think this HashMap is exactly what I need.

Similar Threads

  1. Jexcelapi
    By Psyclone in forum New To Java
    Replies: 2
    Last Post: 01-29-2010, 09:21 AM
  2. Help with arrays!
    By lilac87 in forum New To Java
    Replies: 2
    Last Post: 07-28-2009, 05:57 AM
  3. Arrays
    By swim_fan08 in forum New To Java
    Replies: 7
    Last Post: 04-11-2009, 04:02 PM
  4. new to arrays
    By jimJohnson in forum New To Java
    Replies: 1
    Last Post: 04-08-2008, 03:45 PM
  5. 2D-Arrays
    By kbyrne in forum New To Java
    Replies: 1
    Last Post: 02-07-2008, 11:08 PM

Posting Permissions

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