Advertisement
Guest User

Untitled

a guest
Feb 27th, 2013
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. public class secondClass {
  2. private int hour;
  3. private int minute;
  4. private int second;
  5.  
  6. public newClass(){
  7. this(0,0,0);
  8. }
  9. public newClass(int h){
  10. this(h,0,0);
  11. }
  12. public newClass(int h, int m){
  13. this(h,m,0);
  14. }
  15. public void newClass(int h, int m, int s){
  16. setTime(h,m,s);
  17. }
  18. public void setTime(int h, int m, int s){
  19. setHour(h);
  20. setMinute(m);
  21. setSecond(s);
  22. }
  23. public void setHour(int h){
  24. hour = ((h >= 0 && h <= 24)? h : 0);
  25. }
  26. public void setMinute(int m){
  27. minute = ((m >= 0 && m <= 60)? m : 0);
  28. }
  29. public void setSecond(int s){
  30. second = ((s >= 0 && s <= 60)? s : 0);
  31. }
  32. public int getHour(){
  33. return hour;
  34. }
  35. public int getMinute(){
  36. return minute;
  37. }
  38. public int getSecond(){
  39. return second;
  40. }
  41. public String display(){
  42. return String.format("%d:%02d:%02d %s",((hour == 0 || hour == 12)? 12:hour % 12), minute, second, ((hour < 12)? "am" : "pm") );
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement