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

Videos

Question
Book Icon
Chapter 9, Problem 9PP
Program Plan Intro

Lap Timer using Applet

Program Plan:

Filename: “LapTimerApplication.java”

  • Import the required packages.
  • Declare the class “LapTimerApplication”.
    • Declare the required variables.
    • Define the constructor.
      • Set the window size
      • Close the window.
      • Create an object for “Container” class.
      • Initially set the background color as white.
      • Set the layout.
      • Create the buttons.
      • Add the action to these buttons.
      • Add the buttons on the window screen.
      • Create the object for the labels.
      • Add the label on the window screen.
      • Create an object for the “LapTimer” class.
    • Declare the “actionPerformed” method.
      • Declare the required variables with the values.
      • If the action command is start, then execute the “if” condition.
        • Inside the “try” block, call the method “start ()” and set the labels.
        • In catch block, set the error message.
          • If the action command is lap, then execute the “if” condition.
            • Inside the “try” block, call the method “markLap ()” and set the labels.
            • In catch block, set the error message.
    • Declare the “main ()” method.
      • Create an object for “LapTimer” class.
      • Show the window.

Filename: “LapTimer.java”

  • Import required package
  • Define the class “LapTimer”.
    • Declare required private variables “running”, “startTime”, “lapStart”, “lapTime”, “totalTime”, “lapsCompleted”, “lapsInRace”.
    • Define the constructor.
      • Assign the values.
    • Define the method “start ()”.
      • Check the condition “running == true || lapsCompleted > 0”.
        • Throw “TimerException” exception with a message.
          • Assign “true” to the variable “running”.
          • Calculate the value of “startTime”.
          • Assign the value of “startTime” to “lapStart”.
    • Define the method “markLap ()”.
      • Check if value of “running” is “false”.
        • Check if laps completed are equal to 0.
          • Throw “”TimerException exception with a message.
            • Increment the value of “lapsCompleted”.
            • Get the current time and store it in a variable “currentTime”.
            • Calculate “lapTime” by subtracting “lapStart” from “currentTime”.
            • Calculate “totalTime” by subtracting “startTime” from “currentTime”.
            • Assign the value of “currentTime” to “lapStart”.
            • Check if the value of “lapsCompleted” and “lapsInRace” are equal.
              • Assign “false” to “running”.
    • Define the method “getLapTime ()”.
      • Check if “lapsCompleted” is 0.
        • Throw “”TimerException exception with a message.
            • Return “lapTime”.
    • Define the method “getTotalTime ()”.
      • Check if “lapsCompleted” is 0.
        • Throw “”TimerException exception with a message.
            • Return “totalTime”.
    • Define the method “getLapsRemaining ()”.
      • Return the value.
    • Define the “main ()” function.
      • Declare a variable and assign it with a value.
      • Create an object for the class “LapTimer”.
      • Call the function “start ()”.
      • Call the function “markLap ()”.
      • Print the number of laps.
      • Print the lap time by calling the function “getLapTime ()”.
      • Print the total time by calling the function “getTotalTime ()”.
      • Print the remaining number of laps by calling the function “getLapsRemaining ()”.

Filename: “TimerException.java”

  • Define an exception class named “TimerException”.
    • Define a parameterized constructor for the class.
      • Call the parent class’s method by passing a message.

Blurred answer
Students have asked these similar questions
Use a simple exponential smoothing Method to forecast one-quarter-ahead revenues for Home Depot. Refer to the Home Depot Quarterly.xlsx dataset Year and Quarter Homedepot sales 19811 8.010999978 19812 10.60699999 19813 13.71499997 19814 19.20899999 19821 25.60999996 19822 33.06299996 19823 28.727 19824 30.24599999 19831 42.99299991 19832 66.61299992 19833 64.08299995 19834 82.49499989 19841 95.87199998 19842 119.0679998 19843 100.4589999 19844 117.3799999 19851 145.0479999 19852 174.2389998 19853 177.7179999 19854 203.724 19861 222.619 19862 263.4329996 19863 251.5369997 19864 273.8729992 19871 333.9689999 19872 381.4429998 19873 364.2449999 19874 374 19881 446.5919991 19882 518.1589985 19883 509.9899998 19884 524.7729988 19891 641.5209999 19892 704.0249996 19893 699.7399998 19894 713.2489986 19901 880.855999 19902 990.3459988 19903 936.6119995 19904 1007.542 19911 1186.889999 19912 1352.792 19913…
Write the set of SQL commands necessary to insert the data into the INVOICE table you created in Problem 17, as illustrated in Figure P8.16.
Refer to the shampoo_sales.xlsx time-series dataset. This data shows sales of shampoo over three years monthly. Carry out simple exponential smoothing and Holt's Trend-Corrected on this data and determine whether the data shows any trend. Assume the initial value for the level smoothing parameter (alpha) and Trend smoothing parameter (gamma) is 0.5 Month Sales of shampoo over a three year period 1-Jan 266 1-Feb 145.9 1-Mar 183.1 1-Apr 119.3 1-May 180.3 1-Jun 168.5 1-Jul 231.8 1-Aug 224.5 1-Sep 192.8 1-Oct 122.9 1-Nov 336.5 1-Dec 185.9 2-Jan 194.3 2-Feb 149.5 2-Mar 210.1 2-Apr 273.3 2-May 191.4 2-Jun 287 2-Jul 226 2-Aug 303.6 2-Sep 289.9 2-Oct 421.6 2-Nov 264.5 2-Dec 342.3 3-Jan 339.7 3-Feb 440.4 3-Mar 315.9 3-Apr 439.3 3-May 401.3 3-Jun 437.4 3-Jul 575.5 3-Aug 407.6 3-Sep 682 3-Oct 475.3 3-Nov 581.3 3-Dec 646.9

Chapter 9 Solutions

Java: An Introduction to Problem Solving and Programming (7th 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License