Skip to main content

Debugging lap-timer-buggy

SYSC 2004 Lab 3 Help
Part 4: Debugging lap-timer-buggy Section B
1. Another problem is that clicking the Stop button two or more times in a row causes the display to change repeatedly.
2. Correct this problem.
Part 5: Debugging lap-timer-buggy Section C
1. Finally, several of the values displayed in the window are incorrect.
2. Correct this problem. (Don't forget your testing, including regression testing.) Ensure that you have fixed all the bugs by checking that the "buggy" version now works identically to the "works" version. 
Completed code for lap-timer-buggy below (all changes must be done ONLY in class Timing Engine):
TimingEngine
public class TimingEngine
{
  private boolean running;
  /* The number of laps that the runner has completed. */
  private int lapCount;
  /* The time of the lap just completed, in milliseconds. */
  private long lapTime;
  /* The total time the runner has run so far, in milliseconds. */
  private long totalTime;  
  /* The current time of the system clock when the runner
   * started the current lap, in milliseconds.
   * See getSystemTime(), at the end of this class.
   */
  private long lapStartTime;
  /* The lap length, in metres. */
  private int lapLength;
  /* The average speed, in m/s. */
  private int avgSpeed;   
  public TimingEngine()
  {
    running = false;
    lapCount = 0;
    totalTime = 0;
    lapTime = 0;
    avgSpeed = 0;
    lapLength = 400;
  }
  /**
   * Instruct the timer to start timing a lap.
   * If we were not timing before, this starts the timer for a new 
   * run. If we were already timing, this starts a new lap, adding the
   * current lap time to the total.
   */
  public void startLap()
  {
    if (running) {
      finishLap();
    }
    else {
      lapCount = 0;
      totalTime = 0;
      lapTime = 0;
      lapStartTime = getSystemTime();
      running = true;
    }
  }
  /**
   * Stop timing. Add the current lap time to the total, and set
   * the timer into idle mode (waiting for a new run).
   */
  public void stop()
  {
    finishLap();
    running = false;
  }
  /**
   * Return the current status of the timer. The status is one of the
   * two Strings "Timing..." or "Stopped", indicating whether this 
   * timer is currently running or stopped.
   */
  public String getStatus()
  {
    if (running) {
      return "Timing...";
    }
    else {
      return "Stopped";
    }
  }
  /**
   * Return the number of laps completed in this run.
   */
  public int getLapCount()
  {
    return lapCount;
  }
  /**
   * Return the time of the last lap completed.
   * The result is a string in the format "m:ss:hh", where m is
   * the number of minutes, ss the number of seconds, and hh the number
   * of hundredths of a second. For example "7:02:43".
   */
  public String getLastTime()
  {
    return timeToString(lapTime);
  }
  /**
   * Return the average time for a lap in this run.
   * The result is a string in the format "m:ss:hh".
   */
  public String getAverageTime()
  {
    if (lapCount == 0) {
      return timeToString(0);
    }
    else {
      long avgTime = totalTime / lapCount;
      return timeToString(avgTime);
    }
  }
  /**
   * Return the total time of the last or current run.
   * The result is a string in the format "m:ss:hh".
   */
  public String getTotalTime()
  {
    return timeToString(totalTime);
  }
  /**
   * Return the average speed in this run in meters per second.
   * The result is a string such as "73 m/s".
   */
  public String getAverageSpeed()
  {
    long totalSeconds = totalTime / 1000;
    if (totalSeconds == 0) {
      return "0 m/s";
    }
    else {
      long avgSpeed = lapLength / totalSeconds;
      return avgSpeed + " m/s";
    }
  }
  /**
   * Return the length of a lap.
   */
  public int getLapLength()
  {
    return lapLength;
  }
  /**
   * Set the length of a lap.
   */
  public void setLapLength(int length)
  {
    if(length > 0)
    {
      lapLength = length;
    }
  }
  /**
   * Private method called whenever a lap is finished. This method
   * updates the statistics.
   */
  private void finishLap()
  {
    lapCount++;
    long lapEndTime = getSystemTime();
    lapTime = lapEndTime - lapStartTime;
    totalTime = totalTime + lapTime;
  }
  /**
   * Convert a time interval in milli-seconds into a String in the
   * format "m:ss:hh".
   */
  private String timeToString(long time)
  {
    long hundredths = (time / 10) % 100;
    long seconds = (time / 1000) % 60;
    long minutes = time / 60000;
    return minutes + ":" + twoDigit(seconds) + ":" + twoDigit(hundredths);
  }
  /**
   * Convert a number into a two-digit String representation.
   */
  private String twoDigit(long number)
  {
    if(number < 10) {
      return "0" + number;
    }
    else {
      return "" + number;
    }
  }
  /**
   * Return the current time of the system clock (in milli-seconds).
   */
  private long getSystemTime()
  {
    return System.currentTimeMillis();
  }
}
LapTimer
public class LapTimer
{
  private TimingEngine engine;
  private UserInterface gui;
  public LapTimer()
  {
    engine = new TimingEngine();
    gui = new UserInterface(engine);
  }
  /**
   * In case the window was closed, show it again.
   */
  public void show()
  {
    gui.setVisible(true);
  }
}

Comments

Popular posts from this blog

Identify and discuss a key milestone in the history of computers that interests you and why.

  Part 1Title: Lab ResponseDiscuss one feature of MS Word and one feature of MS Excel that you found challenging within the lab and why. Examples are WordArt, inserting shapes, adding borders, cell styles, etc. This response should be at least one paragraph in length. Part 2Title: History of Computers Identify and discuss a key milestone in the history of computers that interests you and why. This section should be at least one paragraph. Part 3Title: System Software vs. Application Software In your words, explain the difference between application software and system software as if to another coworker who has limited technical knowledge. Use examples to support your rationalization. This section should be at least two paragraphs. Part 4Title: Blockchain and Cryptocurrency In a minimum of one paragraph each: 1. Conduct some research on the internet and discuss one underlying technology of cryptocurrencies like blockchain, cryptography, distributed ledger technol...

Cybersecurity and Infrastructure Security (CISA)

 Develop a research paper that identifies a specific Department of Homeland Security (DHS) operating agency. Fully describe 1 DHS operating agency from the following list: Cybersecurity and Infrastructure Security (CISA) U.S. Customs and Border Protection (CBP) U.S. Citizenship and Immigration Services (USCIS) Federal Emergency Management Agency (FEMA) U.S. Coast Guard (USCG) U.S. Immigration and Customs Enforcement (ICE) U.S. Secret Service (USSS) Transportation Security Administration (TSA) The information must include a discussion of the selected DHS agency. Identify the agency’s mission, goals, objectives, and metrics. Conduct an analysis of how these mission areas address the threats or challenges. Recommend agency program priorities among the current set of goals, objectives, metrics, or budget items. Justification of all choices is an essential element of this assignment. Reference all source material and citations using APA format. WE OFF...

Discuss how the project

ord count : no idea 1. You are required to write a report on all project activities involved in all the 10 knowledge areas of project management for the entire project life cycle. You should also include a list of the respective PM documents, for example PM Plan, PM Quality Management Plan, Risk management, Procurement, etc. The report must include the activities that are considered before the project is closed out. 2. Discuss how the project quality management plan can provide adequate standards and controls in managing global teams in projects. Your discussion must provide adequate arguments for the need of cultural awareness and legal issues. Regards, The post Discuss how the project appeared first on My Assignment Tutor . Assignment status :  Resolved by our Writing Team Source@ PrimeWritersBay.com GET THIS PAPER COMPLETED FOR YOU FROM THE WRITING EXPERTS   CLICK HERE TO ORDER 100% ORIGINAL PAPERS AT PrimeWritersBay.com NO PLAGIARISM