@heyitsmarcus/

The Clock Program-1

Java

OECS 195 Mario Bucio

fork
loading
Files
  • Main.java

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.6389551635293902","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgTWFpbiB7CiAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJndW1lbnRzKSB7IAogICAgLy9ydW4gdGhlIGNsb2NrIHByb2dyYW0gYXV0b21hdGljYWxseSB1cG9uIGV4ZWN1dGlvbgogICAgQ2xvY2suY2xvY2soKTsKICB9Cn0KCmNsYXNzIENsb2NrIHsKICBwdWJsaWMgc3RhdGljIHZvaWQgY2xvY2soKSB7CiAgICAvLyBnZXQgY3VycmVudCB0aW1lIGFuZCBkYXRlCiAgICBDYWxlbmRhciBub3cgPSBDYWxlbmRhci5nZXRJbnN0YW5jZSgpOwogICAgaW50IGhvdXIgPSBub3cuZ2V0KENhbGVuZGFyLkhPVVJfT0ZfREFZKTsKICAgIGludCBtaW51dGUgPSBub3cuZ2V0KENhbGVuZGFyLk1JTlVURSk7CiAgICBpbnQgbW9udGggPSBub3cuZ2V0KENhbGVuZGFyLk1PTlRIKSArIDE7CiAgICBpbnQgZGF5ID0gbm93LmdldChDYWxlbmRhci5EQVlfT0ZfTU9OVEgpOwogICAgaW50IHllYXIgPSBub3cuZ2V0KENhbGVuZGFyLllFQVIpOwoKICAgIC8vIGRpc3BsYXkgZ3JlZXRpbmcKICAgIGlmIChob3VyIDwgMTIpIHsKICAgICAgU3lzdGVtLm91dC5wcmludGxuKCJHb29kIG1vcm5pbmcuXG4iKTsKICAgIH0gZWxzZSBpZiAoaG91ciA8IDE3KSB7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiR29vZCBhZnRlcm5vb24uXG4iKTsKICAgIH0gZWxzZSB7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiR29vZCBld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ICAgU3lzdGVtLm91dC5wcmludCgiSnVseSIpOwogICAgICBicmVhazsKICAgIGNhc2UgODoKICAgICAgU3lzdGVtLm91dC5wcmludCgiQXVndXN0Iik7CiAgICAgIGJyZWFrOwogICAgY2FzZSA5OgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJTZXB0ZW1iZXIiKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDEwOgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJPY3RvYmVyIik7CiAgICAgIGJyZWFrOwogICAgY2FzZSAxMToKICAgICAgU3lzdGVtLm91dC5wcmludCgiTm92ZW1iZXIiKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDEyOgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJEZWNlbWJlciIpOwogICAgfQoKICAgIC8vIGRpc3BsYXkgdGhlIGRhdGUgYW5kIHllYXIKICAgIFN5c3RlbS5vdXQucHJpbnRsbigiICIgKyBkYXkgKyAiLCAiICsgeWVhciArICIuIik7CiAgfQp9Cg=="},"asBuffer":null},"loaded":true}}
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
import java.util.*;

class Main {
  public static void main(String[] arguments) { 
    //run the clock program automatically upon execution
    Clock.clock();
  }
}

class Clock {
  public static void clock() {
    // get current time and date
    Calendar now = Calendar.getInstance();
    int hour = now.get(Calendar.HOUR_OF_DAY);
    int minute = now.get(Calendar.MINUTE);
    int month = now.get(Calendar.MONTH) + 1;
    int day = now.get(Calendar.DAY_OF_MONTH);
    int year = now.get(Calendar.YEAR);

    // display greeting
    if (hour < 12) {
      System.out.println("Good morning.\n");
    } else if (hour < 17) {
      System.out.println("Good afternoon.\n");
    } else {
      System.out.println("Good evening.\n");
    }

    // begin time message by showing the minutes
    System.out.print("It's");
    if (minute != 0) {
      System.out.print(" " + minute + " ");
      System.out.print((minute != 1) ? "minutes" : "minute");
      System.out.print(" past");
    }

    // display the hour
    System.out.print(" ");
    System.out.print((hour > 12) ? (hour - 12) : hour);
    System.out.print(" o'clock on ");

    // display the name of the month
    switch (month) {
    case 1:
      System.out.print("January");
      break;
    case 2:
      System.out.print("February");
      break;
    case 3:
      System.out.print("March");
      break;
    case 4:
      System.out.print("April");
      break;
    case 5:
      System.out.print("May");
      break;
    case 6:
      System.out.print("June");
      break;
    case 7:
      System.out.print("July");
      break;
    case 8:
      System.out.print("August");
      break;
    case 9:
      System.out.print("September");
      break;
    case 10:
      System.out.print("October");
      break;
    case 11:
      System.out.print("November");
      break;
    case 12:
      System.out.print("December");
    }

    // display the date and year
    System.out.println(" " + day + ", " + year + ".");
  }
}