• Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading an interface array of objects  RSS feed

 
Larissa Perkins
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an assignment where I need to add an interface to an already-created program. I have an array of objects, where each object has a name, price, and priority.

In my original program (which worked), I had all of the objects in 1 class. The professor said that I should split up the name/price/priority into 3 different classes. So what I have is an array that belongs to an interface, and name/price/priority implements. But I am having trouble loading the data into the array (from another class) once I am done with loading name.

Here is what I have so far.









Line 18 in the ItemName class is giving me an error, and I know it is because arr is of type Interface, and I am trying to assign is a String. But I don't know how to do this. In my original program I was able to do arr[x].getName(); but when I do that in Main, I get errors.

I know there are probably tons of errors, but I can't find anything online that can tell me how to assign to an interface array from multiple classes. Can this even be done?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to step back from the nuts and bolts details and figure out exactly what you're trying to do. It's hard to figure out what to do with a bunch of cogs, gears, bars, nuts, and bolts (interfaces, classes, etc.) if you don't have a very clear idea of what kind of machine you want to make and what exactly that machine is going to do. StopCoding (←click) and try to describe what you want to happen irrespective of details like Java classes and/or interfaces or what not.

I see there's already some kind of hint in the code you posted: "Your Shopping List" so tell us exactly what you'd like this Shopping List program to do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!