• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Implementing Matrix interface to handle 2D array as object

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
   I am attempting to implement an interface named Matrix and then perform various functions on the new Matrix objects. I cannot seemed to get passed go for this (college) assignment.  When I initiate a new Matrix object and pass in a 2D array, I lose the ability to access any of the indexes in the array. I know it cannot be this difficult to implement. I haven't really accomplished anything because I cannot get go far without the ability to access the elements in the arrays. Can anyone explain how to avoid this? I can find many implementations of interfaces but can't find any that convert an array to an object and then modify the contents. I have attached the interface, as well as my (lack) of code. I have essentially been stuck between lines 2-9 because without the ability to access elements, there is no point in writing anything further. Any help would be great.


 
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you storing a Matrix variable rather than the original 2D array?
 
R L Miller
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not sure honestly, I attempted to store a 2D array but then I have some methods below that require a Matrix return type, then I tried to change the return types to int[][] and received an error that I am no longer implementing Matrix. I could have written this program without the interface in less than 10 minutes and I have been spending hours trying to utilize this interface to no avail. This makes me think I am missing something simple and obvious.
 
Jeanne Boyarsky
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your instinct to store to the 2D array was correct. Try to make just this code compile first. Then write hash code/equals/toString. Then write the other methods. That will give you a stable base to build up form.

 
Marshal
Posts: 80616
468
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:. . . write hash code/equals/toString.  . . .

But go through the Arrays class before you do; you may find some useful information there which makes writing those methods much much easier.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic