Results 1 to 2 of 2
  1. #1
    lam5442 is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default What is best object to create?

    Hi,

    Basically, I have a matrix that has been created using a double array. For each block of the matrix, I need to store four numbers. I cannot determine what kind of object/data structure I need to use in which to store these numbers. I know that I can create an object, and I would love to be able to say something like "firstvalue = matrix[i][j].firstvalue" in my driver program, but how would I go about storing firstvalue in my matrix object, especially since that currently is the name of my array?

    Thanks,
    lam5442

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Reads like you need a class that will hold four double values and then store an instance of this class in each block of the array/matrix. Remember to set accessor and set methods in your class so you can retrieve the four values e.g. of one of the methods
    Java Code:
    public double getX(){
       return x; // where x is a member of class
    }
    Array storing and retrieving - (presume myClass is an instance of that class that holds 4 doubles say call it DoubleClass) and myMatrix is a 2d array of type DoubleClass (can hold objects of DoubleClass)
    Java Code:
    myMatrix[i][j]=myClass; // assign
    double value=myMatrix[i][j].getX(); // retrieve doubles

Similar Threads

  1. Create new Calendar object???
    By aliencc in forum New To Java
    Replies: 4
    Last Post: 01-17-2011, 02:19 PM
  2. Replies: 2
    Last Post: 06-22-2010, 05:29 AM
  3. create object
    By paul21 in forum New To Java
    Replies: 4
    Last Post: 03-07-2010, 08:14 PM
  4. create object with name from string
    By skandalouz in forum New To Java
    Replies: 7
    Last Post: 12-06-2009, 12:40 AM
  5. how to create an object at runtime
    By sireesha in forum New To Java
    Replies: 8
    Last Post: 10-01-2008, 01:52 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
  •