• 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

Return type required

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This public Retailitem() is giving me this error, not sure why, to the naked eye it looks just like my example, probably a simple fixed.
Says invalid method declaration return type required,
This is a class a demo uses.



 
Ranch Hand
Posts: 31
Opera C++ Notepad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it should be capital i (I)in Retailitem.plesae make change in the constructor.
 
Nick Harms
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok now its saying cannot find symbol - class item in the demo. on the item one = new RetailItem(); line. Why is that? It matches the class name.
 
Nick Harms
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Never mind I got it, should be RetailItem one= new RetailItem();
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Harms wrote:Never mind I got it, should be RetailItem one= new RetailItem();



or *may be* you forget to implements *Item* interface . and,

remember : Constructor name must be same as class name

 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nick,

Why do you have an empty constructor? Does it ever make sense to have an item with no information in this program?

You can use the overloaded constructor how it's supposed to and get rid of the setter method calls in your demo class. if it's a requirement to use the setter methods, you can use a



inside the overloaded constructor.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#
# public double getUnitsOnHand()
# {
# return UnitsOnHand;
# }

should have an 'int' return type not a 'double'

 
Saul Groene
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
# //Display object 1 info
# System.out.println(" Item 1 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + one.getdescription());
# System.out.println("Units on hand: " + one.UnitsOnHand());
# System.out.println("Price: " + one.Price);
#
# //Display object 2 info
# System.out.println(" Item 2 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + two.getdescription());
# System.out.println("Units on hand: " + two.UnitsOnHand());
# System.out.println("Price: " + two.Price);
#
# //Display object 3 info
# System.out.println(" Item 3 Information" );
# System.out.println("====================================");
# System.out.println("Description: " + three.getdescription());
# System.out.println("Units on hand: " + three.UnitsOnHand());
# System.out.println("Price: " + three.Price);
#


The bolded method calls above should be the 'getter' methods ie... three.getUnitsOnHand() instead of what is there..
 
Janeice DelVecchio
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Saul,

Welcome to Java Ranch!

Please remember to use code tags... it helps format the code to make it easier to read

Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic