• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error: The constructor Day(int, int, int) is undefined  RSS feed

 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I resently started programing with java using Eclipse and i am atm trying to make a code that tells me the difrent amount of days between 2 dates.
I wrote the code like this:
package test1;

public class Sallyslife {

public static void main(String[] args) {
Day birthday = new Day(1951, 5, 26);
Day LastDay = new Day(2012, 2, 2);
int daysAlive = LastDay.daysFrom(birthday);
System.out.println(daysAlive);
}

}

and when i run it i get this error and i do not know what to do.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Day(int, int, int) is undefined
The constructor Day(int, int, int) is undefined
The method daysFrom(Day) is undefined for the type Day
Can anyone help me?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What is the class "Day"? It's not a class in the standard Java class libraries, so it should be something that your code defines. Or did you mean the "Date" class? In that case you need to import it from the java.util package.

Update:
Or did you mean the "Date" class?

Apparently not, because that has no "daysFrom" method.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the error messages it can be seen that the code you are trying to call is non-existent...

You haven't created a constructor in the Day class that takes three ints as arguments and you haven't created the method daysFrom(Day)... so the compiler halts in confusion
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, i see what you are saying. But how do i create constructor in the Day class that takes three ints as arguments and how do i create a method days From(Day)(do you mean days From(birthday)?) . ( I have a hard time even understanding what you mean(no explanation failure just me being experience i believe.)
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ulf, i dont mean date. Day is (i belive) what varibel type that handle dates? Is this what you were asking for?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your replies I must ask the question, how are you learning the Java Programming Langauge? From a book? Website?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan stenkvist wrote:Hmm, i see what you are saying. But how do i create constructor in the Day class that takes three ints as arguments and how do i create a method days From(Day)(do you mean days From(birthday)?) . ( I have a hard time even understanding what you mean(no explanation failure just me being experience i believe.)


You can't use something that doesn't exist. To use the Day class, you need to either (1) write one, or (2) get a copy of it. Based on your code, I am assuming that your instructor provided you with the class?

Henry
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using alitel bit off everything. Mostly guides/tutorials from the internet and a book called "The Java Tutorial objekt oriented programming for the internet"
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not in a class were i am learning it. I am doing it on my owne from home.
How do i know what to write in the Day class?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can start here

 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will check it out, thanks alot
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ehh, i do not know why that happend to "alot"
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To add a quick synopsis...

Java consist of mainly two categories for you to store information which are primitive types defined by the language and Object types defined by programmers...

The primitive types have predefined characteristics such as storage space and which operations can be performed on them... These include boolean, char, byte, short, int, long, float, double

The Object type allow you the programmer to create a new type to determine exactly how much storage space is required and what kind of operations can be performed on this new type...

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan stenkvist wrote:I am using alitel bit off everything. Mostly guides/tutorials from the internet and a book called "The Java Tutorial objekt oriented programming for the internet"


Basically, you got an incomplete example... so, either (1) go back to the original location, and get the rest of the source, or (2) go back and see if it was meant to actually compile. It could just be a coding example that wasn't meant to be complete. Sometime books and tutorial do that.

Henry
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read the link that you posted but i still dont know what to do.
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is meent to be used and is not just a example
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan stenkvist wrote:The code is meent to be used and is not just a example


Then find the rest of the code -- because what you showed us is incomplete.

Henry
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the tutorials for thorough explanation of creating a class... Your Day class could be created as follows:


Now you can use this newly created type as follows:


Now you can use this example and experiment with it as you like while referring to the tutorials to further understand and enhance your knowledge...
 
Dan stenkvist
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan stenkvist wrote:Ehh, i do not know why that happend to "alot"

There are some words that automatically generate a link in your post. Alot is one of them. You can avoid it in future by remembering that that phrase is actually two words in English
Thanks a lot
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Will that daysFrom method actually calculate the difference in days?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!