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: 78% (14 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
-
In the United States, labor receives about 70 percent of national income, and capital receives about 30 percent. If total factor productivity increases by 1 percent, labor increases by 1 percent, and...
-
What the following words mean to you: leadership, leader, follower and leading.
-
On December 31, Year 1, Kelly Corporation of Toronto paid 13 million Libyan dinars (LD) for 100% of the outstanding common shares of Arkenu Company of Libya. On this date, the fair values of Arkenu's...
-
Altira Inc. has sales revenue of $1,330,000 resulting in an operating income of $172,900. Average investment in assets total $380,000and the cost of capital (hurdle rate) is 17%. What is the...
-
Which of the graphs in Fig. Q25.12 best illustrates the current I in a real resistor as a function of the potential difference V across it? Explain. Figure Q25.12 (a) (b) (c) (d)
-
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...
-
With regard to electron configuration, what do all the elements in Group VIIA of the periodic table have in common?
-
How would you explain the following code in plain English? boxplot(age ~ gender, data = donors) Question 8 options: Make a boxplot comparing gender grouped by age, using the donors dataset Make two...
-
Vision Consulting Inc. began operations on January 1, 2019. Its adjusted trial balance at December 31, 2020 and 2021 is shown below. Other information regarding Vision Consulting Inc. and its...
-
A Jeans maker is designing a new line of jeans called Slams. Slams will sell for $290 per unit and cost $182.70 per unit In variable costs to make. Fixed costs total $68,500. (Round your answers to 2...
-
NAME: Week Two Define Claim in your own words Explain the difference between a discussion and an argument. Summarize the characteristics of a claim (Listing is not summarizing) Define Status Quo in...
-
1.How do you think major stores such as Walmart will change in the future under this new retail renaissance? 2.What are some changes that you would suggest in traditional retail stores to attract...
-
When a force of 2 lb is applied to the handles of the brad squeezer, it pulls in the smooth rod AB. Determine the force P exerted on each of the smooth brads at C and D. 2 lb 0.25 in.-2 in. Ez 1.5...
-
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...
-
At December 31, 2020. Cord Company's plant asset and accumulated depreciation and amortization accounts had balances as follows: Plant Asset $ 179,000 Accumulated Depreciation and Antortization $...
-
In 2003, Sotheby's the auctioneer sold a mustang 1955 for a price of $10,341,500. The owner who sold the car had purchased the Mustang in 1999 at a price of $12,437,500 from a rich celebrity. What...
-
XYZ Corp is expected to grow earnings at 15% over the next few years. XYZs current P/E is 42 and their expected earnings per share next year is $3.00. Calculate the target price objective for XYZ.
Study smarter with the SolutionInn App