Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return type required

 
Nick Harms
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • 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.



 
ahamed irshad
Ranch Hand
Posts: 31
C++ Notepad Opera
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Never mind I got it, should be RetailItem one= new RetailItem();
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • 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

 
Janeice DelVecchio
Saloon Keeper
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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.
 
Saul Groene
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 1808
12
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic