如何在我的代码行中正确设置 totalSeconds() (时分秒)和 return
How to properly set totalSeconds() (hours minutes seconds) in my line of code and return it
大家好,我的老师给了我一个时钟程序,它必须 return 信息等,到目前为止我对总秒数应该如何工作有点困惑,我会展示我的 driver 和下面的正常文件,请帮助。我必须确保总秒数的时分秒数 return。我将 post 对我的代码进行实时编辑
我尝试通过添加一个变量并将其添加到 driver 中来 [=22=] 它,但无济于事。
{
//Instance Variables
private int Hours;
private int Minutes;
private int Seconds;
private double Cost;
private boolean IsOn;
private int DLS;
//Zero arg constructors
public Clock()
{ // Start
Hours = 10;
Minutes = 52;
Seconds = 23;
Cost = 20.00;
IsOn = true;
DLS = 11;
} // End
//Multi-Argument Constructors
public Clock( int Hours, int Minutes, int Seconds, double Cost , boolean IsOn, int DSL)
{ // Start
this.Hours = Hours;
this.Minutes = Minutes;
this.Seconds = Seconds;
this.Cost = Cost;
this.IsOn = IsOn;
this.DLS = DLS;
} // End
public void setTime(int Hours)
{
System.out.println(Hours + 1);
}
public int convertDaylightSaving(int Hours)
{
return Hours;
}
//ToString Method
public String toString()
{ //Start
String output;
output = "When I checked my watch the hour was: " + Hours + "\n" +
"When I checked my watch the minute was: " + Minutes + "\n" +
"When I checked my watch the seconds were: " + Seconds + "\n" +
"The Cost is: " + Cost + "\n" +
"Is this the time right now?: " + IsOn;
return output;
}
} // End
public class ClockDriver
{
public class ClockDriver
{ // Start
public static void main(String[] args)
{ // Officially Start
Clock Watch = new Clock( 11, 04, 16, 35.99, false, 11);
System.out.println(Watch);
} // End
} // Officially End
预期的结果是把我做的都打印出来,结果报错
好的,我实际上通过执行以下操作回答了我自己的问题。
public class Clock
{
//Instance Variables
private int Hours;
private int Minutes;
private int Seconds;
private double Cost;
private boolean IsOn;
private int DLS;
int totalSeconds;
//Zero arg constructors
public Clock()
{ // Start
Hours = 10;
Minutes = 52;
Seconds = 23;
Cost = 20.00;
IsOn = true;
DLS = 11;
totalSeconds = 9945;
} // End
//Multi-Argument Constructors
public Clock( int Hours, int Minutes, int Seconds, double Cost , boolean IsOn, int DSL, int totalSeconds)
{ // Start
this.Hours = Hours;
this.Minutes = Minutes;
this.Seconds = Seconds;
this.Cost = Cost;
this.IsOn = IsOn;
this.DLS = DLS;
this.totalSeconds = totalSeconds;
} // End
public void setTime(int Hours)
{
System.out.println(Hours + 1);
}
public int convertDaylightSaving(int Hours)
{
return Hours;
}
public int totalSeconds()
{
return totalSeconds + 5000;
}
//ToString Method
public String toString()
{ //Start
String output;
output = "When I checked my watch the hour was: " + Hours + "\n" +
"When I checked my watch the minute was: " + Minutes + "\n" +
"When I checked my watch the seconds were: " + Seconds + "\n" +
"The Cost is: " + Cost + "\n" +
"Is this the time right now?: " + IsOn + "\n" +
"The total seconds right now are: " + totalSeconds;
return output;
}
} // End
之后我制作了驱动程序并拥有它return
public class ClockDriver
{ // Start
public static void main(String[] args)
{ // Officially Start
Clock Watch = new Clock( 11, 04, 16, 35.99, false, 11, 9945);
System.out.println(Watch);
}
} // End
大家好,我的老师给了我一个时钟程序,它必须 return 信息等,到目前为止我对总秒数应该如何工作有点困惑,我会展示我的 driver 和下面的正常文件,请帮助。我必须确保总秒数的时分秒数 return。我将 post 对我的代码进行实时编辑
我尝试通过添加一个变量并将其添加到 driver 中来 [=22=] 它,但无济于事。
{
//Instance Variables
private int Hours;
private int Minutes;
private int Seconds;
private double Cost;
private boolean IsOn;
private int DLS;
//Zero arg constructors
public Clock()
{ // Start
Hours = 10;
Minutes = 52;
Seconds = 23;
Cost = 20.00;
IsOn = true;
DLS = 11;
} // End
//Multi-Argument Constructors
public Clock( int Hours, int Minutes, int Seconds, double Cost , boolean IsOn, int DSL)
{ // Start
this.Hours = Hours;
this.Minutes = Minutes;
this.Seconds = Seconds;
this.Cost = Cost;
this.IsOn = IsOn;
this.DLS = DLS;
} // End
public void setTime(int Hours)
{
System.out.println(Hours + 1);
}
public int convertDaylightSaving(int Hours)
{
return Hours;
}
//ToString Method
public String toString()
{ //Start
String output;
output = "When I checked my watch the hour was: " + Hours + "\n" +
"When I checked my watch the minute was: " + Minutes + "\n" +
"When I checked my watch the seconds were: " + Seconds + "\n" +
"The Cost is: " + Cost + "\n" +
"Is this the time right now?: " + IsOn;
return output;
}
} // End
public class ClockDriver
{
public class ClockDriver
{ // Start
public static void main(String[] args)
{ // Officially Start
Clock Watch = new Clock( 11, 04, 16, 35.99, false, 11);
System.out.println(Watch);
} // End
} // Officially End
预期的结果是把我做的都打印出来,结果报错
好的,我实际上通过执行以下操作回答了我自己的问题。
public class Clock
{
//Instance Variables
private int Hours;
private int Minutes;
private int Seconds;
private double Cost;
private boolean IsOn;
private int DLS;
int totalSeconds;
//Zero arg constructors
public Clock()
{ // Start
Hours = 10;
Minutes = 52;
Seconds = 23;
Cost = 20.00;
IsOn = true;
DLS = 11;
totalSeconds = 9945;
} // End
//Multi-Argument Constructors
public Clock( int Hours, int Minutes, int Seconds, double Cost , boolean IsOn, int DSL, int totalSeconds)
{ // Start
this.Hours = Hours;
this.Minutes = Minutes;
this.Seconds = Seconds;
this.Cost = Cost;
this.IsOn = IsOn;
this.DLS = DLS;
this.totalSeconds = totalSeconds;
} // End
public void setTime(int Hours)
{
System.out.println(Hours + 1);
}
public int convertDaylightSaving(int Hours)
{
return Hours;
}
public int totalSeconds()
{
return totalSeconds + 5000;
}
//ToString Method
public String toString()
{ //Start
String output;
output = "When I checked my watch the hour was: " + Hours + "\n" +
"When I checked my watch the minute was: " + Minutes + "\n" +
"When I checked my watch the seconds were: " + Seconds + "\n" +
"The Cost is: " + Cost + "\n" +
"Is this the time right now?: " + IsOn + "\n" +
"The total seconds right now are: " + totalSeconds;
return output;
}
} // End
之后我制作了驱动程序并拥有它return
public class ClockDriver
{ // Start
public static void main(String[] args)
{ // Officially Start
Clock Watch = new Clock( 11, 04, 16, 35.99, false, 11, 9945);
System.out.println(Watch);
}
} // End