Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot find constructor

 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class



Demo


Error of cannot find symbol
Symbol: contstructor Teamleader()
Location: class TeamLeader leader1 = -->n <-- ew TeamLeader();

I thought I was doing everything right for the first time, my TeamLeader class even compiles, but when i try to draw from it, no bueno. Please help.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why am I unable to edit posted thread, the file is missing two } at the end..
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shall I add the }}? You ought to be indenting your code; that is the point of code tags, to maintain indentation. I presume you have found the preview button, so you can see what the post looks like before committing it.

The reason it won’t compile is that you need to pass arguments to the constructor. Your class requires 5 arguments, so you must pass 5 arguments.
By the way, those arguments are confusing. 5 counts as a lot, and the names you have given (ep) are not at all informative. There is a risk of getting the arguments out of order, particularly with so many of them.
Why is training required an int? There is some dubious logic in using a number for that.
 
Antriksh jain
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ben.

The problem with your code is you have use parameterized construtor.
public TeamLeader(int ep, int pn, double b, int tr, int ta)
{
prodNum = pn;
empProd = ep;
bonus = b;
trainingRequired = tr;
trainingAttended = ta
}

but your defalult contructor is missing. Add code before parameterized contrutor as:
public TeamLeader()
{
}
By default java provide a default contrutor.But if are defining contrutor from your own it will not provide any default contrutor.

let me know it is not working

Thanks.

 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Antriksh jain wrote: . . .. Add code before parameterized contrutor as:
public TeamLeader()
{
}
. . .
No, don’t do that at all.
Unless having 0 for all those values is a valid state for the object to be in, do not provide a no‑args constructor alongside your several‑args constructor.
You will have been told that constructors are there to allow creation of an object. They are also there to restrict object creation: in this case it only works if you supply the 5 parameters.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Antriksh jain.
I would have added code tags to your post, which you should always use, but you hadn’t indented the code, so it wouldn’t have improved it much.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Antriksh jain wrote: . . .. Add code before parameterized contrutor as:
public TeamLeader()
{
}
. . .
No, don’t do that at all.
Unless having 0 for all those values is a valid state for the object to be in, do not provide a no‑args constructor alongside your several‑args constructor.
You will have been told that constructors are there to allow creation of an object. They are also there to restrict object creation: in this case it only works if you supply the 5 parameters.


gimme a second i'll try it out.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TeamLeader tl = new TeamLeader(123, 234, 345.67, 678, 789);
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have problems because you have not overridden the toString() method. It will compile and run and give you a disappointing output.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so.... after looking at what you guys spoke of something clicked in my head. I was making something so simple way too complicated.

I went from the code you see above to....



The demo now works ;)
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you everyone.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49411
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You’re welcome
If I were marking it, I would take lots of marks off for the poor field names. Also for inappropriate use of Strings for the bonus.
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The demo now works ;)

Not as posted I'm afraid, unless you have a written your own class called 'string'

Your TeamLeader class extends PorductionWorker. I think this should be ProductionWorker.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am more then open to improvement. I don't understand the string comment
 
Aj Prieto
Ranch Hand
Posts: 75
Android Chrome Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you check over your code, you should check for capitalization.

What Tony was referring to is that String should be capitalized.

Also in your first post where it says it can't find "Teamleader()", the "L" should have been capitalized and be passed the appropriate arguments.
 
Ben Calvin
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the clarity. The mistakes pointed out were, besides the horrendous naming convention, due to me retyping the entire files. Everything works as planned. I will look more into constructors further besides the adding the statements in the class. I think I will review the early chapters on naming convention as well. This place is a really good resource.
 
Tony Docherty
Bartender
Posts: 2965
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's very important when posting code to a forum that you do it via copy and paste rather than typing it in. If you type it in and make a mistake (which is easy to do as you have discovered) then you are wasting our time getting us to help you solve a problem that isn't even in the code you are running.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic