Java 如何在我的代码行中正确设置totalSeconds()(小时-分钟-秒)并返回它

Java 如何在我的代码行中正确设置totalSeconds()(小时-分钟-秒)并返回它,java,methods,constructor,getter-setter,Java,Methods,Constructor,Getter Setter,嘿,伙计们,我的老师给了我一个时钟程序,它必须返回信息等等,到目前为止,我对总秒数应该如何工作有点困惑,我将在下面显示我的驱动程序和普通文件,请帮助。我必须确保小时、分钟和秒以秒为单位返回。我将发布我对代码所做的实时编辑 我试图通过添加一个变量并将其添加到驱动程序中来返回它,但没有结果 { //Instance Variables private int Hours; private int Minutes; private int Seconds; private dou

嘿,伙计们,我的老师给了我一个时钟程序,它必须返回信息等等,到目前为止,我对总秒数应该如何工作有点困惑,我将在下面显示我的驱动程序和普通文件,请帮助。我必须确保小时、分钟和秒以秒为单位返回。我将发布我对代码所做的实时编辑

我试图通过添加一个变量并将其添加到驱动程序中来返回它,但没有结果

{

  //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 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

在那之后,我让司机回来了

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

在修复编译问题之前,代码将无法运行。例如,
this.Time=Time-您没有
时间
。另外,
public void setTime(int Hours,Minutes,Seconds)
Minutes
Seconds
没有类型。而且,
public int convertDaylightSave(整数小时+1)
也不合法。基本上,你发布的代码需要大量的修复。我修复了所有这些。谢谢你,它是编译的,我只是不知道从哪里开始转换到第二个。如果你做这些作业,代码非常混乱。我不建议复制和粘贴,有太多的漏洞会让你的老师大吃一惊
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