Revise Programming Exercise 2.8 to display the hour using a 12-hour clock. Here is a sample run:
Question:
Revise Programming Exercise 2.8 to display the hour using a 12-hour clock. Here is a sample run:
Listing 2.7, ShowCurrentTime.java, gives a program that displays the current time in GMT. Revise the program so that it prompts the user to enter the time zone offset to GMT and displays the time in the specified time zone. Here is a sample run:
Transcribed Image Text:
Enter the time zone offset to GMT: -5 The current time is 4:50:34 AM -Enter 1 public class ShowCurrentTime { 2 public static void main(String [] args) { // Obtain the total milliseconds since midnight, Jan 1, 1970 long totalMilliseconds = System.currentTimeMillis(); 3 // Obtain the total seconds since midnight, Jan 1, 1970 long totalSeconds = totalMilliseconds / 1000; // Compute the current second in the minute in the hour long currentSecond = totalSeconds % 60; 10 11 // Obtain the total minutes long totalMinutes = totalSeconds / 60; 12 13 totalMinutes 14 // Compute the current minute in the hour long currentMinute = totalMinutes % 60; 15 16 currentMinute 17 // Obtain the total hours long totalHours = totalMinutes / 60; 18 19 totalHours 20 // Compute the current hour long currentHour = totalHours % 24; 21 22 currentHour 23 // Display results System.out.println("Current t ime is " + currentHour + + currentMinute + ":" + currentSecond + " GMT"); 24 25 26 27 preparing output 28 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 84% (13 reviews)
Program plan Prompt the user to enter the time zone offset to GMT Calculate the current time for giv...View the full answer
Answered By
Prajwal kalpande
i am teaching for 10 class student
0.00
0 Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Revise Programming Exercise 3.15 to add an additional $2,000 award if two digits from the user input are in the lottery number. Write a program that prompts the user to enter an integer for today?s...
-
Revise Programming Exercise 31.1 to write a server for multiple clients. Write a server for a client. The client sends loan information (annual interest rate, number of years, and loan amount) to the...
-
Programming Exercise 3.32 shows how to test whether a point is on an unbounded line. Revise Programming Exercise 3.32 to test whether a point is on a line segment. Write a program that prompts the...
-
discusses how a reseller can service both a consumer and an industrial market from the same store location. Provide an example of a retailer and detail the differences in their marketing activities.
-
Determine the domain of the function. 7. 9. (x) = x4 + (x 1)3 11. g(y) = 10 y+y1 G(11) = u2-4
-
Assuming stall-on-branch and no delay slots, what speedup is achieved on this code if branch outcomes are determined in the ID stage, relative to the execution where branch outcomes are determined in...
-
A snow-cone machine at an icecream shop costs \(\$ 15,000\). The machine is expected to generate profits of \(\$ 2,500\) each year of its 10-year useful life. At the end of the 10 years, the machine...
-
Three Point Sports Inc. manufactures basketballs for the Womens National Basket-ball Association (WNBA). For the first 6 months of 2017, the company reported the following operating results while...
-
Find the solution of the equation coth x = a, assuming that a > 1. Express the result in terms of elementary functions of a. [Hint: The result should have the form x = f(a), where f(a) is a specific...
-
1. Discuss the success of LOrals slogan Because Im worth it over time and how it has managed to connect with women. What is the role of cosmetics in the way women of different ages look at themselves...
-
Write a program that prompts the user to enter the center coordinates and radii of two circles and determines whether the second circle is inside the first or overlaps with the first, as shown in...
-
Write a program that prompts the user to enter the exchange rate from currency in U.S. dollars to Chinese RMB. Prompt the user to enter 0 to convert from U.S. dollars to Chinese RMB and 1 to convert...
-
Why would an e-marketer choose to use competitor positioning? Integrator positioning?
-
Our company has reviewed the utilities bills for our company. We have determined that the highest and lowest bills were $5,000 and $3,200 for the months of January and September. If we produced 1,050...
-
A mass of 5 kg stretches a spring 1 0 cm . The mass is acted on by an external force of 1 0 * sin ( t / 2 ) N ( newtons ) and moves in a medium that imparts a viscous force of 2 N when the speed of...
-
Suppose you buy a sleek Italian racing automobile (e.g. Fiat) and you have the choice of paying the full price, $41,000, now; or $10,000 at the end of each of the next five years. What is the cost of...
-
An AC circuit contains a resister of 20.052, an inductor of 74.0m H and a variable capacitor. If the frequency of the applied voltage is 423 Hz, what setting should the capacitor be set if resonance...
-
A helium neon laser ( = 6 3 0 nm ) is used in a single - slit experiment with a screen 2 . 0 m away from the slit. If the slit is 0 . 2 2 mm wide, what is the width of the central bright fringe on...
-
During the year, Wind and Solar Power Ltd. Issued $1 million of common shares in exchange for windmill equipment. Geoff, the chief financial officer, argues that the acquisition of equipment is an...
-
Show that gj concave AHUCQ Abadie For nonnegative variables, we have the following corollary.
-
Design a class named Date that meets the following requirements: Three data fields year, month, and day for representing a date A constructor that constructs a date with the specified year, month,...
-
Design a class named Point that meets the following requirements: Two data fields x and y for representing a point with getter methods A no-arg constructor that constructs a point for (0, 0) A...
-
The book uses LinkedList for buckets. Replace LinkedList with AVLTree. Assume E is Comparable. Redefine MyHashSet as follows: public class MyHashSet> implements Collection { ... } Test your program...
-
The purpose of this assignment is to better understand what the important pieces of the Linux/Unix operating system that you might want to prioritize reviewing when you are doing a forensic...
-
What is the function of the Helix system? What are the benefits of this tool? How does it work in terms of digital evidence collection? How do you get evidence of Unix, Linux, and Mac OS operating...
-
Analyzing revenue, expense, and withdrawal transactions into debit and credit parts Use the chart of accounts for Hals Marketing Services given in Application Problem 2-2. Transactions: Mar. 25. Sold...
Study smarter with the SolutionInn App