• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Instantiate 3 instances

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need help with instantiating 3 instances of the RetailItem

 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do I use two IF statements or only one? Or an If Else statement?
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic