Skip to content

Commit 93b5ba7

Browse files
authored
Add files via upload
My programs I've made so far using Think Java. Also a test of using Github.
1 parent 7302e62 commit 93b5ba7

4 files changed

Lines changed: 79 additions & 0 deletions

File tree

CelciusToFarenheit.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import java.util.Scanner;
2+
3+
public class SecondsConverter{
4+
}

Date.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
public class Date {
2+
3+
public static void main(String[] args){
4+
String day = "Wednesday";
5+
String month = "May";
6+
int date = 9;
7+
int year = 2018;
8+
9+
printAmerican(day,date,month,year);
10+
printEuropean(day,date,month,year);
11+
12+
}
13+
14+
public static void printAmerican(String day, int date, String month, int year){
15+
//prints a date in American format
16+
System.out.println("American format: " + day + ", " + month + " " + date + ", " + year + ".");
17+
}
18+
19+
public static void printEuropean(String day, int date, String month, int year){
20+
//prints a date in European format
21+
System.out.println("European format: " + day + " " + date + " " + month + " " + year + ".");
22+
}
23+
24+
}

SecondsConverter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* Converts seconds into hours, minutes, seconds
5+
*/
6+
public class SecondsConverter{
7+
8+
public static void main(String[] args){
9+
int seconds;
10+
Scanner in = new Scanner(System.in);
11+
//user inputs amount of seconds
12+
System.out.print("Amount of seconds to convert: ");
13+
seconds = in.nextInt();
14+
//conversions for seconds into minutes, seconds, hours
15+
final int HOURS = (seconds / 3600);
16+
final int MINUTES_REMAINDER = (seconds % 3600);
17+
final int MINUTES = (MINUTES_REMAINDER / 60);
18+
final int SECONDS = (MINUTES_REMAINDER % 60);
19+
//displays seconds into hours, minutes, seconds
20+
System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds", seconds, HOURS, MINUTES, SECONDS);
21+
}
22+
}

Time.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class Time {
2+
public static void main(String[] args) {
3+
//time when i started this code
4+
int hour = 2;
5+
int minute = 53;
6+
int second = 12;
7+
//time when i finished this code
8+
int newHour = 3;
9+
int newMinute = 10;
10+
int newSecond = 13;
11+
int secondsPerDay = (24 * 3600);
12+
int secondsSinceMidnight = (hour * 3600) + (minute * 60) + second;
13+
int newSecondsSinceMidnight = (newHour * 3600) + (newMinute * 60) + newSecond;
14+
double secondsPerDayDbl = (24 * 3600);
15+
double secondsSinceMidnightDbl = (hour * 3600) + (minute * 60) + second;
16+
double percentagePassed = (secondsSinceMidnightDbl / secondsPerDayDbl);
17+
18+
//displays how many seconds have passed since midnight
19+
System.out.println("There have been " + secondsSinceMidnight + " seconds since midnight");
20+
//displays how many seconds left in a day
21+
System.out.println("There are " + (secondsPerDay - secondsSinceMidnight) + " seconds left in this day.");
22+
//displays the percentage of the day that has passed
23+
System.out.println(percentagePassed + "% of the day has passed.");
24+
//displays time that has passed since I started programming this
25+
System.out.println((newSecondsSinceMidnight - secondsSinceMidnight) +
26+
" seconds have passed since you wrote this code");
27+
28+
}
29+
}

0 commit comments

Comments
 (0)