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

    Default What is best object to create?


    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?


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


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