• Post Reply Bookmark Topic Watch Topic
  • New Topic

Instantiate 3 instances  RSS feed

 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help with instantiating 3 instances of the RetailItem

 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1st error: do you have a RetailItem constructor that takes no parameters ?
2nd error: You are uisng a different method to what you use on lines 8 and 13. Is that the reason ?
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you write the class yourself? Whenever you write a class, write a constructor. Write as few constructors as you can, but always write one. If you have a constructor which is actually accessible (see this Java Language Specification page), make sure that constructor leaves your object in a consistent state. That means, every constructor should leave every field of the class set to a sensible value.
Then, you have some constructors which are accessible from outside the class. You say you have certain parameters. That means you are saying, “If you want to instantiate my class, you have to provide the folliowng information:….”

Your class has a constructor, which has certain parameters. Somebody calls that constructor, they have to provide arguments which match those parameters. If you compiler complains, you have provided the wrong information, and you need to ensure you call the constructor with arguments which match its requirements. Look at the constructors in the retail item class, and make sure to call it with arguments matching its parameters.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the exact error message(s) that you are receiving. Be sure to UseCodeTags to preserve the formatting.
 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help! I'm so dumb. Something so simple I made it so difficult and complicated. I resolved it within the parameters.

Now for my next step, any pointers would be greatly appreciated.




 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The instructions seem quite clear; which part are you having difficulty with?
 
Anthony Ross
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do I use two IF statements or only one? Or an If Else statement?
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Draw a diagram showing the possible paths of execution from the instructions given. you should be able to tell how many branches that has; each branch is an if. A two‑way branch is an if‑else, and a three‑way branch is an if‑else if‑else. A two‑way branch where one branch does nothing is an if.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!