Sounds a little stupid, but I need help on my toString()
method and it is very irking.
I tried looking up online because the toString
is the one where it is screwing up and "not finding Kid constructor #2" even though it is there and I would even do something else and it doesn t work.
Ok that was a lot so here is my code:
import java.util.*;
class Kid {
String name;
double height;
GregorianCalendar bDay;
public Kid () {
this.name = "HEAD";
this.height = 1;
this.bDay = new GregorianCalendar(1111,1,1);
}
public Kid (String n, double h, String date) {
// method that toString() can t find somehow
StringTokenizer st = new StringTokenizer(date, "/", true);
n = this.name;
h = this.height;
}
public String toString() {
return Kid(this.name, this.height, this.bDay);
}
} //end class
Ok,所以我上面的线条(我知道,我的第三个参数关闭了,应该是一个字符串)关闭了。如果我硬码了第三个参数的值,它就会变得干燥,说它找不到(上面的)这个(上面的)。所以我怎样才能找到日期并打破它呢?
班级呼叫这里在下面
class Driver {
public static void main (String[] args) {
Kid kid1 = new Kid("Lexie", 2.6, "11/5/2009");
System.out.println(kid1.toString());
} //end main method
} //end class
I tried researching multiple constructors and it really didn t help.
I tried researching toString()
methods, and tried using previous toString()
methods logic that I created previous but this is brand new so it never worked.
帮助?