Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Java-Assignment-002.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="21" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
54 changes: 54 additions & 0 deletions src/Time.java
Original file line number Diff line number Diff line change
@@ -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.");

}
}