Как правильно установить totalSeconds () (часы, минуты, секунды) в моей строке кода и вернуть его - PullRequest
0 голосов
/ 25 октября 2019

Привет, ребята, мой учитель дал мне программу для создания часов, она должна возвращать информацию и т. Д. Пока я немного запутался в том, как должно работать общее количество секунд, ниже я покажу свой драйвер и обычный файл, пожалуйста. Помогите. Я должен убедиться, что часы, минуты и секунды возвращаются в общем количестве секунд. Я буду публиковать живые изменения, внесенные в мой код

Я пытался вернуть его, добавив переменную и добавив его в драйвер безрезультатно.

{

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

Ожидаемыйрезультаты для него - распечатать все, что я сделал, результат - ошибки.

1 Ответ

0 голосов
/ 25 октября 2019

Хорошо, поэтому я на самом деле ответил на свой вопрос, выполнив следующее.



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