• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overloaded constructor not being implemented?  RSS feed

 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, even though I am giving it the correct number of arguments for the constructor to be initalized it doesn't go through. I end up with a compile error: PatientBuilder.java:17: error:

constructor Patient in class Patient cannot be applied to given types;
Patient aPatient = new Patient(bloodType, rhFactor, ID, age);
^
required: no arguments
found: String,String,int,int
reason: actual and formal argument lists differ in length

And I'm not understanding how that's possible when it calls for 2 strings and 2 ints and that's what I am passing. Does anyone have any ideas?


I have this in my main method

And then here are my two constructors, one default and one overloaded.

 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you compiling this?
It's possible an old version of Person.class is still on the classpath.

Are you sure this is the version of Person referred to?
Is there another source file on the classpath?

Those two would be my candidates.
 
Daniel Gurianov
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Try to replace with nextLine
 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright guy's I deleted a lot of corrupt files of this program and then I don't know I moved around a lot of stuff but now it works! I am still confused as to what exactly happened to make everything corrupt but it's whatever I guess. Thanks for trying to help me out!!
 
Daniel Gurianov
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please disregard my upper comment.

Please post all code cause it is time consuming to rev-code all missed components.
Here below is compilable version of what you`ve posted.




 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michaell Sam wrote:Alright guy's I deleted a lot of corrupt files of this program and then I don't know I moved around a lot of stuff but now it works! I am still confused as to what exactly happened to make everything corrupt but it's whatever I guess. Thanks for trying to help me out!!


IDE's can sometimes get confused.
It's why there's usually a "Clean and Build" option...
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That isn't a default constructor. You never write a default constructor, but let the compiler add it for you.
That no‑arguments constructor is positively dangerous. You don't only use constructors to allow instantiation of classes, but also to restrict it. The 4‑arguments constructor tell people you need 4 arguments to create an object. The 0‑arguments constructor tells users you can easily guess the blood group and kill the patient. I hope you will understand why I think that constructor should be delete.
 
Michaell Sam
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see what you're saying Ritchie, I wouldn't have made that constructor if it was not required as part of the assignment, thanks for the tip though!
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mention it to whoever set the assignment and see what they say.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!