Biodata dan Time Class
Berikut merupakan contoh penggunaan pemrograman berbasis objek untuk menampilkan biodata dan waktu universal serta standar.
Source code biodata:
Tampilan:
Source code Class Time:
Source Code Class Timeset
Tampilan Time:
Source code biodata:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /** * Write a description of class biodata here. * * @author (your name) * @version (a version number or a date) */ public class biodata { public biodata (){ System.out.println("Nama : Wisnu"); System.out.println("NRP : 05111740000170"); System.out.println("Kelas : PBO D"); System.out.println("Departemen: INFORMATIKA"); } } |
Tampilan:
Source code Class Time:
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 | /** * Write a description of class time here. * * @author (your name) * @version (a version number or a date) */ public class time1 { private int hour; private int minute; private int second; public void setTime (int h, int m, int s) { if ((h>- 0 && h < 24 ) && (m >- 0 && m < 60 ) && ( s >- 0 && s < 60)) { hour = h; minute = m; second = s; } else throw new IllegalArgumentException( "hour, minute and/or second was out of range"); } public String toUniversalString() { return String.format ("%02d:%02d:%02d", hour, minute, second); } public String toString () { return String.format ("%d:%02d:%02d %s", (( hour == 0 || hour == 12) ? 12 : hour % 12), minute, second, (hour < 12 ? "AM" : "PM")); } } |
Source Code Class Timeset
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 | /** * Write a description of class time here. * * @author (your name) * @version (a version number or a date) */ public class time1 { private int hour; private int minute; private int second; public void setTime (int h, int m, int s) { if ((h>- 0 && h < 24 ) && (m >- 0 && m < 60 ) && ( s >- 0 && s < 60)) { hour = h; minute = m; second = s; } else throw new IllegalArgumentException( "hour, minute and/or second was out of range"); } public String toUniversalString() { return String.format ("%02d:%02d:%02d", hour, minute, second); } public String toString () { return String.format ("%d:%02d:%02d %s", (( hour == 0 || hour == 12) ? 12 : hour % 12), minute, second, (hour < 12 ? "AM" : "PM")); } } |
Tampilan Time:
Komentar
Posting Komentar