方法和构造函数
如何使用内部有代码的方法?
public void initialiseVariables(){
name=timestamp.substring(0, 20);
// numofdep = timestamp.substring(35, 37);
//noofovertime = timestamp.substring(38, 40);
if(timestamp.charAt(20)=='C')
city=true;
if(timestamp.charAt(21)=='U')
union=true;
identificationnumber=Integer.parseInt(timestamp.substring(22,26));//to get an integer from a string use the integer.parseint
numofdep = Integer.parseInt(timestamp.substring(35, 37));
noofovertime = Integer.parseInt(timestamp.substring(38, 40));
hoursworked=Integer.parseInt(timestamp.substring(27,29));
hourlyrate = Double.parseDouble( timestamp.substring(30, 34));
}
我不明白你在构造函数中放入了什么。另外,如何确定参数中放入的内容?就像我朋友写的这个构造函数。
Employees(){
this.timestamp=timestamp;
initialiseVariables();
}
那么我该如何
name=timestamp.substring(0, 20);
在我的主类中使用这条线呢?
How do you use a method with code inside in?
public void initialiseVariables(){
name=timestamp.substring(0, 20);
// numofdep = timestamp.substring(35, 37);
//noofovertime = timestamp.substring(38, 40);
if(timestamp.charAt(20)=='C')
city=true;
if(timestamp.charAt(21)=='U')
union=true;
identificationnumber=Integer.parseInt(timestamp.substring(22,26));//to get an integer from a string use the integer.parseint
numofdep = Integer.parseInt(timestamp.substring(35, 37));
noofovertime = Integer.parseInt(timestamp.substring(38, 40));
hoursworked=Integer.parseInt(timestamp.substring(27,29));
hourlyrate = Double.parseDouble( timestamp.substring(30, 34));
}
I don't understand what you put inside the constructor. Also how do you determine what you put inside the parameters? like this constructor my friend wrote.
Employees(){
this.timestamp=timestamp;
initialiseVariables();
}
So how do I use for example the line,
name=timestamp.substring(0, 20);
in my main class?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
推荐阅读
班级员工:
班级主要:
Recommended reading
Class Employees:
Class Main:
您的构造函数是错误的,您写道:
您必须将构造函数构造为以下形式:
此构造函数有一个参数并将其设置为自己的对象成员(时间戳)并调用初始成员。
你必须读java core,《Thinking In Java》之类的书对你有帮助。
请充分利用您的方式以获得更好的帮助。
your constructor is wrong, you write :
you have to constructor to following form :
this constructor has one parameter and set that to own object member(timestamp) and call initial member.
You have to read java core, books such as "Thinking In Java" help you.
please your means completely for better help.
看起来你在能走到这里之前就想先跑。我强烈建议您观看 theNewBoston 在 YouTube 上发布的以下教程视频。
http://www.youtube.com/watch?NR=1& ;v=SHIT5VkNrCg&feature=fvwp
只需花一些时间观看这些视频就会让您的事情变得更加轻松。我理解当你的老师把所有事情都扔给你而没有太多帮助时是什么感觉。这些视频会有帮助。
有时他会犯一些错误,但他的视频是我发现的最好的入门视频。祝你好运 :)
It's looking like you're trying to run before you can walk here. I'd strongly suggest taking a look at the following tutorial vidoes on youtube by theNewBoston.
http://www.youtube.com/watch?NR=1&v=SHIT5VkNrCg&feature=fvwp
Just spending some time watching these videos will make things MUCH easier for you. I understand what it's like when you have a teacher that throws everything at you without much help. Those videos will help.
Sometimes he gets things a little wrong, but his videos are the best I've found for getting started. Good luck :)