-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchedule.java
More file actions
90 lines (77 loc) · 3.28 KB
/
Schedule.java
File metadata and controls
90 lines (77 loc) · 3.28 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.util.Scanner;
import javax.lang.model.util.ElementScanner6;
import java.util.*;
import java.io.*;
import java.text.DecimalFormat;
public class Schedule{
public static void main(String args []) throws IOException
{
Scanner sc = new Scanner(System.in);
// try {
// File file = new File(args[0]);
// sc = new Scanner(file);
// }catch(IOException e){
// System.out.println("I/O error");
// }
int n = sc.nextInt();
while(n != 0)
{
double amTimes [] = new double [100];
double pmTimes [] = new double [100];
double noons [] = new double [100];
double midnights [] = new double [100];
int amCount = 0;
int pmCount = 0;
int noonCount = 0;
int midnightCount =0;
for(int i =0; i < n; i++)
{
String time = sc.next();
String aP = sc.next();
String value = time.replace(":", ".");
if(aP.charAt(0) == 'a' && Double.parseDouble(value) < 12)
{
amTimes[i] = Double.parseDouble(value);
amCount++;
}else if(aP.charAt(0) == 'p' && Double.parseDouble(value) < 12){
pmTimes[i] = Double.parseDouble(value);
pmCount++;
}else if(aP.charAt(0) == 'a' && Double.parseDouble(value) >= 12)
{
midnights[i] = Double.parseDouble(value);
midnightCount++;
}else
{
noons[i] = Double.parseDouble(value);
noonCount++;
}
}
Arrays.sort(amTimes);
Arrays.sort(pmTimes);
Arrays.sort(noons);
Arrays.sort(midnights);
final DecimalFormat df = new DecimalFormat("#0.00");
for(int i = midnights.length - (midnightCount); i < midnights.length; i++)
{
System.out.println(df.format(midnights[i]).replace(".", ":") + " a.m.");
}
for(int i = amTimes.length - (amCount); i < amTimes.length; i++)
{
System.out.println(df.format(amTimes[i]).replace(".", ":") + " a.m.");
}
for(int i = noons.length - (noonCount); i < noons.length; i++)
{
System.out.println(df.format(noons[i]).replace(".", ":") + " p.m.");
}
for(int i = pmTimes.length - (pmCount); i < pmTimes.length; i++)
{
System.out.println(df.format(pmTimes[i]).replace(".", ":") + " p.m.");
}
n = sc.nextInt();
if(n != 0)
{
System.out.println();
}
}
} //make two arrays for noons and print in reverse
}