听起来有点愚蠢,但我的toString()方法需要帮助,这非常令人讨厌.我尝试在网上查找,因为toString它正在搞砸,"没有找到Kid构造函数#2",即使它在那里,我甚至会做别的事情,但它不起作用.好的,这就是我的代码:
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
Run Code Online (Sandbox Code Playgroud)
好吧所以我上面的toString(我知道,我的第三个参数是关闭的,应该是一个字符串)是关闭的.如果我硬编码第三件事的价值它会变得混乱,并说它找不到这个(上面).那么我怎样才能获得日期并将其分解?
调用此类的课程如下
class Driver {
public static …Run Code Online (Sandbox Code Playgroud) java ×1