Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Implementing Matrix interface to handle 2D array as object  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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: 38906
684
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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: 38906
684
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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: 61710
193
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!