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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Database Systems For Advanced Applications Dasfaa 2023 International Workshops Bdms 2023 Bdqm 2023 Gdma 2023 Bundlers 2023 Tianjin China April 17 20 2023 Proceedings Lncs 13922

Authors: Amr El Abbadi ,Gillian Dobbie ,Zhiyong Feng ,Lu Chen ,Xiaohui Tao ,Yingxia Shao ,Hongzhi Yin

1st Edition

3031354141, 978-3031354144

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago