Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a new class called TimedResponse . Declare two LocalDateTime objects. These objects will hold the exact time before a user is prompted and the

Create a new class called TimedResponse. Declare two LocalDateTime objects. These objects will hold the exact time before a user is prompted and the exact time after the user responds. Also declare two integers to hold the value of the seconds for both times. The difference between these two value is the elapsed time between the creations of the two LocalDateTime values.

Assign the current time into the first LocalDateTime object, and then extract the value of the current seconds field.

LocalDateTime time1 = LocalDateTime.now(); int secs1 = time1.getSecond();

Display a dialog box that asks the user to make a difficult choice.

JOptionPane.showConfirmDialog(null, "Are you a closet Taylor Swift fan?");

Next, get the system time immediately after the user responds to the dialog box, and extract its seconds component.

LocalDateTime time2 = LocalDateTime.now(); int secs2 = time2.getSecond();

Compute the difference between the times and display the result in a dialog box.

JOptionPane.showMessageDialog(null, "End seconds: " + secs2 + " Start seconds: " + secs1 + " It took " + difference + " seconds for you to answer. Was it a difficult decision?");

Save and run the program. When the question appears, ponder for a few seconds and then choose a response.

The output is only accurate when the first and second LocalDateTime objects are created during the same minute. If the first object is created 58 seconds after a minute starts and the user doesn't respond to the question until 2 seconds after the next minute starts, the difference between the two values will be calculated incrrectly as -56 instead of 4 seconds. Modify the application to fix this problem. (Hint, you'll have to use getMinute() too.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions