From e5bd5bf33e6cd86304fa70f58177228e881e7a67 Mon Sep 17 00:00:00 2001 From: Ricardo M <95rikym@gmail.com> Date: Sun, 28 Jan 2024 19:32:44 -0800 Subject: [PATCH] The deed is done, in just under an hour! --- .idea/vcs.xml | 6 +++++ Java-Assignment-002.iml | 1 + src/Time.java | 54 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 .idea/vcs.xml create mode 100644 src/Time.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Assignment-002.iml b/Java-Assignment-002.iml index b46c0dd..7b67cbe 100644 --- a/Java-Assignment-002.iml +++ b/Java-Assignment-002.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/src/Time.java b/src/Time.java new file mode 100644 index 0000000..b787f73 --- /dev/null +++ b/src/Time.java @@ -0,0 +1,54 @@ +public class Time { + public static void main(String[] args) { + System.out.println("Hello World!\n"); + + int hour; + int minute; + int second; + + // Following the example program in Section 2.4 of your book, + // define variables named hour, minute, and second. + // Assign values that approximate the current time. + // Use a 24-hour clock (e.g., set hour to 14 for 2:00 PM). + + hour = 18; + minute = 43; + second = 54; + + int currentTime = (hour * 3600) + (minute * 60) + second; + + //Implement the program to calculate and display the number of seconds since midnight. + System.out.println("The number of seconds since midnight is: " + currentTime); + + //Extend the program to calculate and display the number of seconds remaining in the day. + int secondsInADay = 86400; + + int secondsRemaining = secondsInADay - currentTime; + + + System.out.println("The seconds remaining in the day are: " + secondsRemaining); + + System.out.println("Total seconds in a day = " + (secondsRemaining + currentTime)); + + //Further enhance the program to calculate and display the percentage of the day that has passed. + // Be cautious when dealing with percentages using integers; consider using floating-point numbers. + + double percentagePassed = (double) currentTime / secondsInADay * 100; + + System.out.println("\nThe percentage of the day since midnight is: " + percentagePassed + "%"); + + //Modify the values of hour, minute, and second to reflect the current time. + // Then, write code to compute the elapsed time since you started working on this exercise. + + hour = 19; + minute = 23; + second = 27; + + int currentTimeNow = (hour * 3600) + (minute * 60) + second; + + + System.out.println("\n" + + "Time, in seconds, worked on this program: " + (currentTimeNow - currentTime) + " = 39.55 mins."); + + } +} \ No newline at end of file