@mariobucio/

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.6490991210380834","path":"Main.java","file":{"path":"Main.java","content":{"asEncoding":{"base64":"aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgQ2xvY2sgewogIHB1YmxpYyBzdGF0aWMgdm9pZCBNYWluKFN0cmluZ1tdIGFyZ3VtZW50cykgewogICAgLy8gZ2V0IGN1cnJlbnQgdGltZSBhbmQgZGF0ZQogICAgQ2FsZW5kYXIgbm93ID0gQ2FsZW5kYXIuZ2V0SW5zdGFuY2UoKTsKICAgIGludCBob3VyID0gbm93LmdldChDYWxlbmRhci5IT1VSX09GX0RBWSk7CiAgICBpbnQgbWludXRlID0gbm93LmdldChDYWxlbmRhci5NSU5VVEUpOwogICAgaW50IG1vbnRoID0gbm93LmdldChDYWxlbmRhci5NT05USCkgKyAxOwogICAgaW50IGRheSA9IG5vdy5nZXQoQ2FsZW5kYXIuREFZX09GX01PTlRIKTsKICAgIGludCB5ZWFyID0gbm93LmdldChDYWxlbmRhci5ZRUFSKTsKCiAgICAvLyBkaXNwbGF5IGdyZWV0aW5nCiAgICBpZiAoaG91ciA8IDEyKSB7CiAgICAgIFN5c3RlbS5vdXQucHJpbnRsbigiR29vZCBtb3JuaW5nLlxuIik7CiAgICB9IGVsc2UgaWYgKGhvdXIgPCAxNykgewogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkdvb2QgYWZ0ZXJub29uLlxuIik7CiAgICB9IGVsc2UgewogICAgICBTeXN0ZW0ub3V0LnByaW50bG4oIkdvb2QgZXZlbmluZy5cbiIpOwogICAgfQoKICAgIC8vIGJlZ2luIHRpbWUgbWVzc2FnZSBieSBzaG93aW5nIHRoZSBtaW51dGVzCiAgICBTeXN0ZW0ub3V0LnByaW50KCJJdCdzIik7CiAgICBpZiAobWludXRlICE9IDApIHsKICAgICAgU3lzdGVtLm91dC5wcmludCgiICIgKyBtaW51dGUgKyAiICIpOwogICAgICBTeXN0ZW0ub3V0LnByaW50KChtaW51dGUgIT0gMSkgPyAibWludXRlcyIgOiAibWludXRlIik7CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIiBwYXN0Iik7CiAgICB9CgogICAgLy8gZGlzcGxheSB0aGUgaG91cgogICAgU3lzdGVtLm91dC5wcmludCgiICIpOwogICAgU3lzdGVtLm91dC5wcmludCgoaG91ciA+IDEyKSA/IChob3VyIC0gMTIpIDogaG91cik7CiAgICBTeXN0ZW0ub3V0LnByaW50KCIgbydjbG9jayBvbiAiKTsKCiAgICAvLyBkaXNwbGF5IHRoZSBuYW1lIG9mIHRoZSBtb250aAogICAgc3dpdGNoIChtb250aCkgewogICAgY2FzZSAxOgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJKYW51YXJ5Iik7CiAgICAgIGJyZWFrOwogICAgY2FzZSAyOgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJGZWJydWFyeSIpOwogICAgICBicmVhazsKICAgIGNhc2UgMzoKICAgICAgU3lzdGVtLm91dC5wcmludCgiTWFyY2giKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDQ6CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIkFwcmlsIik7CiAgICAgIGJyZWFrOwogICAgY2FzZSA1OgogICAgICBTeXN0ZW0ub3V0LnByaW50KCJNYXkiKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDY6CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIkp1bmUiKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDc6CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIkp1bHkiKTsKICAgICAgYnJlYWs7CiAgICBjYXNlIDg6CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIkF1Z3VzdCIpOwogICAgICBicmVhazsKICAgIGNhc2UgOToKICAgICAgU3lzdGVtLm91dC5wcmludCgiU2VwdGVtYmVyIik7CiAgICAgIGJyZWFrOwogICAgY2FzZSAxMDoKICAgICAgU3lzdGVtLm91dC5wcmludCgiT2N0b2JlciIpOwogICAgICBicmVhazsKICAgIGNhc2UgMTE6CiAgICAgIFN5c3RlbS5vdXQucHJpbnQoIk5vdmVtYmVyIik7CiAgICAgIGJyZWFrOwogICAgY2FzZSAxMjoKICAgICAgU3lzdGVtLm91dC5wcmludCgiRGVjZW1iZXIiKTsKICAgIH0KCiAgICAvLyBkaXNwbGF5IHRoZSBkYXRlIGFuZCB5ZWFyCiAgICBTeXN0ZW0ub3V0LnByaW50bG4oIiAiICsgZGF5ICsgIiwgIiArIHllYXIgKyAiLiIpOwogIH0KfQo="},"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
import java.util.*;

class Clock {
  public static void Main(String[] arguments) {
    // 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 + ".");
  }
}