-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeThem.java
More file actions
75 lines (53 loc) · 1.97 KB
/
Copy pathTimeThem.java
File metadata and controls
75 lines (53 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*# Name : Cristian Z-GhostlyCris
# Class: CSET 1200
# Instructor: Dr. Jared Oluoch
# Programming Assignment: 1
# Date: 9/6/2021
# Summary: Calculates area of triangle based on user input
Problem 4
Write a program that prompts the user to enter his/her name,
and the seconds (e.g one million). The program displays
the user's name and the number of hours and minutes.
Here is a sample run:
Enter your name: Auko Otieno
Enter the seconds: 15000
Hello, Auko Otieno.
15000 seconds is 4 hours and 10 minutes.*/
import java.util.Scanner;
public class TimeThem {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
//Ask user for name
System.out.print("Please enter your first and last name: ");
String name = input.nextLine();
//declare variables set and constants
final int MIN = 60, HRS = 3600, DYS = 84600;
int days, seconds, minutes, hours, rDays, rHours;
//Ask user for time in seconds
System.out.println("Please enter time in as seconds: ");
int inputs = input.nextInt();
//Calculate with less headache
days = inputs/DYS;
rDays = inputs%DYS;
hours = rDays/HRS;
rHours = rDays%HRS;
minutes = rHours/MIN;
seconds = rHours%MIN;
//int hours = (seconds % 86400 ) / 3600 ;
//int minutes = ((seconds % 86400 ) % 3600 ) / 60 ;
//Print everything
System.out.println("Hello, "+ name);
//
//System.out.println(inputs + " Seconds is " + hours + " and " + minutes + " minutes." );
//System.out.println("Or this many days " + days);
if (inputs >= HRS ) {
System.out.println(inputs + " seconds is " + hours + " hours " + minutes + " minutes " + seconds + " seconds");
}
else if (inputs >= MIN && inputs < HRS) {
System.out.println(inputs + " seconds is " + minutes + " minutes " + seconds + " seconds");
}
else (inputs < MIN) {
System.out.println(inputs + " seconds is seconds");
}
}
}