Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Videos

Textbook Question
Book Icon
Chapter 9, Problem 13E

Write a class LapTimer that can be used to time the laps in a race. The class should have the following private attributes:

  • running — a boolean indication of whether the timer is running
  • startTime — the time when the timer started
  • lapStart — the timer’s value when the current lap started
  • lapTime — the elapsed time for the last lap
  • totalTime — the total time from the start of the race through the last completed lap
  • lapsCompleted — the number of laps completed so far
  • lapsInRace — the number of laps in the race

The class should have the following methods:

  • LapTimer (n) — a constructor for a race having n laps.
  • start — starts the timer. Throws an exception if the race has already started.
  • markLap — marks the end of the current lap and the start of a new lap. Throws an exception if the race is finished.
  • getLapTime — returns the time of the last lap. Throws an exception if the first lap has not yet been completed.
  • getTotalTime — returns the total time from the start of the race through the last completed lap. Throws an exception if the first lap has not yet been completed.
  • getLapsRemaining — returns the number of laps yet to be completed, including the current one.

Express all times in seconds.

To get the current time in milliseconds from some baseline date, invoke

Calendar.getInstance ().getTimeInMillis ()

This invocation returns a primitive value of type long. By taking the difference between the returned values of two invocations at two different times, you will know the elapsed time in milliseconds between the invocations. Note that the class Calendar is in the package java.util.

Blurred answer
Students have asked these similar questions
Rectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables).  Remember that a Rectangle has two attributes: Length and Width.  Implement the class by creating a computer program that will ask the user about three rectangle dimensions.  The program should be able to display the total area of the three rectangle objects.  For this exercise, you are required to apply all OOP concepts that you learned in class.   Sample output: Enter Length R1:  1 Enter Width  R1:  1 Enter Length R2:  2 Enter Width  R2:  2 Enter Length R3:  3 Enter Width  R3:  3 The total area of the rectangles is 14.00   Note:  All characters in boldface are user inputs.
Dice Rolling Class In this problem, you will need to create a program that simulates rolling dice. To start this project, you will first need to define the properties and behaviors of a single die that can be reused multiple times in your future code. This will be done by creating a Dice class. Create a Dice class that contains the following members: Two private integer variables to store the minimum and maximum roll possible. Two constructors that initialize the data members that store the min/max possible values of rolls. a constructor with default min/max values. a constructor that takes 2 input arguments corresponding to the min and max roll values Create a roll() function that returns a random number that is uniformly distributed between the minimum and maximum possible roll values. Create a small test program that asks the user to give a minValue and maxValue for a die, construct a single object of the Dice class with the constructor that initializes the min and max…
Using Visual Studio C# Language Note: not a User Input

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License