diff --git a/Date.java b/Date.java new file mode 100644 index 0000000..7c0f00d --- /dev/null +++ b/Date.java @@ -0,0 +1,24 @@ +public class Date { + + public static void main(String[] args){ + String day = "Wednesday"; + String month = "May"; + int date = 9; + int year = 2018; + + printAmerican(day,date,month,year); + printEuropean(day,date,month,year); + + } + + public static void printAmerican(String day, int date, String month, int year){ + //prints a date in American format + System.out.println("American format: " + day + ", " + month + " " + date + ", " + year + "."); + } + + public static void printEuropean(String day, int date, String month, int year){ + //prints a date in European format + System.out.println("European format: " + day + " " + date + " " + month + " " + year + "."); + } + +} \ No newline at end of file diff --git a/SecondsConverter.java b/SecondsConverter.java new file mode 100644 index 0000000..f942564 --- /dev/null +++ b/SecondsConverter.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +/** + * Converts seconds into hours, minutes, seconds + */ +public class SecondsConverter{ + + public static void main(String[] args){ + int seconds; + Scanner in = new Scanner(System.in); + //user inputs amount of seconds + System.out.print("Amount of seconds to convert: "); + seconds = in.nextInt(); + //conversions for seconds into minutes, seconds, hours + final int HOURS = (seconds / 3600); + final int MINUTES_REMAINDER = (seconds % 3600); + final int MINUTES = (MINUTES_REMAINDER / 60); + final int SECONDS = (MINUTES_REMAINDER % 60); + //displays seconds into hours, minutes, seconds + System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds", seconds, HOURS, MINUTES, SECONDS); + } +} diff --git a/Time.java b/Time.java new file mode 100644 index 0000000..14890f3 --- /dev/null +++ b/Time.java @@ -0,0 +1,29 @@ +public class Time { + public static void main(String[] args) { + //time when i started this code + int hour = 2; + int minute = 53; + int second = 12; + //time when i finished this code + int newHour = 3; + int newMinute = 10; + int newSecond = 13; + int secondsPerDay = (24 * 3600); + int secondsSinceMidnight = (hour * 3600) + (minute * 60) + second; + int newSecondsSinceMidnight = (newHour * 3600) + (newMinute * 60) + newSecond; + double secondsPerDayDbl = (24 * 3600); + double secondsSinceMidnightDbl = (hour * 3600) + (minute * 60) + second; + double percentagePassed = (secondsSinceMidnightDbl / secondsPerDayDbl); + + //displays how many seconds have passed since midnight + System.out.println("There have been " + secondsSinceMidnight + " seconds since midnight"); + //displays how many seconds left in a day + System.out.println("There are " + (secondsPerDay - secondsSinceMidnight) + " seconds left in this day."); + //displays the percentage of the day that has passed + System.out.println(percentagePassed + "% of the day has passed."); + //displays time that has passed since I started programming this + System.out.println((newSecondsSinceMidnight - secondsSinceMidnight) + + " seconds have passed since you wrote this code"); + + } +}