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

问题描述 投票:0回答:1

嗨,我的老师给了我一个时钟程序,它必须返回信息,等等,到目前为止,我对应该工作的总秒数有些困惑,我将在下面显示我的驱动程序和普通文件,请帮助。我必须确保“时分秒”以总秒数返回。我将发布对代码进行的实时修改]

我试图通过添加变量并将其添加到驱动程序中以无济于事地返回它。

{

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

预期的结果是它打印出我所做的一切,结果是它出错了。

java methods constructor getter-setter
1个回答
0
投票

好,所以我实际上通过执行以下操作回答了自己的问题。

© www.soinside.com 2019 - 2024. All rights reserved.