| 1 | /* |
| 2 | 0 ;) harvie@harvie-ntb prg $ java clock 1234567890- |
| 3 | Clock: |
| 4 | |
| 5 | ### ### ### ### ### ### ### ### |
| 6 | # # # # # # # # # # # # # # |
| 7 | # # # # # # # # # # # # # # |
| 8 | ### ### ### ### ### ### ### ### |
| 9 | # # # # # # # # # # # # # |
| 10 | # # # # # # # # # # # # # |
| 11 | ### ### ### ### ### ### |
| 12 | */ |
| 13 | |
| 14 | class digital { |
| 15 | public String[] digits = new String[5]; |
| 16 | public StringBuffer[] digit = new StringBuffer[5]; |
| 17 | |
| 18 | public void next_digit() { |
| 19 | int i; |
| 20 | for(i=4;i>=0;i--) digits[i]=digits[i]+" "+digit[i]; |
| 21 | for(i=4;i>=0;i--) digit[i]=new StringBuffer(" "); |
| 22 | } |
| 23 | |
| 24 | public void segment(int i) { |
| 25 | switch(i) { |
| 26 | case 1: digit[0]=new StringBuffer(" --- "); break; |
| 27 | case 4: digit[2]=new StringBuffer(" --- "); break; |
| 28 | case 7: digit[4]=new StringBuffer(" --- "); break; |
| 29 | case 2: digit[1].setCharAt(0,'|'); break; |
| 30 | case 3: digit[1].setCharAt(4,'|'); break; |
| 31 | case 5: digit[3].setCharAt(0,'|'); break; |
| 32 | case 6: digit[3].setCharAt(4,'|'); break; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public void segments(String segs) { |
| 37 | for(int i=segs.length()-1;i>=0;i--) segment( Integer.parseInt(Character.toString(segs.charAt(i))) ); |
| 38 | } |
| 39 | |
| 40 | public void numero(int i) { |
| 41 | switch(i) { |
| 42 | case 0: segments("123567"); break; |
| 43 | case 1: segments("36"); break; |
| 44 | case 2: segments("13457"); break; |
| 45 | case 3: segments("13467"); break; |
| 46 | case 4: segments("2346"); break; |
| 47 | case 5: segments("12467"); break; |
| 48 | case 6: segments("124567"); break; |
| 49 | case 7: segments("136"); break; |
| 50 | case 8: segments("1234567"); break; |
| 51 | case 9: segments("12346"); break; |
| 52 | default: segments("4"); break; |
| 53 | } |
| 54 | next_digit(); |
| 55 | } |
| 56 | public digital() { |
| 57 | int i; |
| 58 | for(i=4;i>=0;i--) digit[i]=new StringBuffer(""); |
| 59 | for(i=4;i>=0;i--) digits[i]=new String(""); |
| 60 | next_digit(); |
| 61 | } |
| 62 | |
| 63 | public void parse(String str) { |
| 64 | for(int i=0;i<str.length();i++) { |
| 65 | try { |
| 66 | numero( Integer.parseInt(Character.toString(str.charAt(i))) ); |
| 67 | } catch(Exception e) { |
| 68 | numero(-1); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | public void print() { |
| 74 | int i; |
| 75 | for(i=0;i<5;i++) { |
| 76 | System.out.println(digits[i]); |
| 77 | if(i == 1 || i == 3) System.out.println(digits[i]); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | public class clock { |
| 83 | public static void main(String[] argv) { |
| 84 | if(argv.length != 1) { System.out.println("Usage: java clock 22:10"); System.exit(0); } |
| 85 | System.out.println("Clock:\n"); |
| 86 | digital d = new digital(); |
| 87 | //for(int i=-1;i<=9;i++) d.numero(i); |
| 88 | //d.parse("12:10"); |
| 89 | d.parse(argv[0]); |
| 90 | d.print(); |
| 91 | |
| 92 | } |
| 93 | } |