Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. package aufg_74;
  2.  
  3. public class Time {
  4. private int hour;
  5. private int minutes;
  6.  
  7. //Aufgabenstellung beachten
  8. Time(int h, int m){
  9. this.hour = h;
  10. this.minutes = m;
  11. }
  12.  
  13. //bleibt unberuehrt
  14. int getHour(){
  15. return hour;
  16. }
  17.  
  18. //bleibt unberuehrt
  19. int getMinutes(){
  20. return minutes;
  21. }
  22.  
  23. //Aufgabenstellung beachten
  24. int timeInMinutesFromZero(){
  25. int min = this.minutes + (this.hour * 60);
  26. return min;
  27. }
  28.  
  29.  
  30. //Aufgabenstellung beachten
  31. boolean isSameTimeAs(Time a){
  32. if(this.hour == a.hour && this.minutes == a.minutes)
  33. return true;
  34. else
  35. return false;
  36. }
  37.  
  38. //Aufgabenstellung beachten
  39. boolean isLaterThan(Time a){
  40. if(this.hour>a.hour ||this.hour == a.hour && this.minutes >a.minutes)
  41. return true;
  42. else
  43. return false;
  44. }
  45.  
  46. //Aufgabenstellung beachten
  47. Time timeInTimeFormat(int min){
  48. int a = min/60;
  49. int erg = a * 60;
  50. int b = min - erg;
  51.  
  52. return new Time(a,b);
  53. }
  54.  
  55. //Aufgabenstellung beachten
  56. int distanceInMinTo(Time a){
  57. int i = this.timeInMinutesFromZero();
  58. int j = a.timeInMinutesFromZero();
  59. if (i>=j)
  60. return i-j;
  61. else
  62. return j-i;
  63. }
  64.  
  65. //Aufgabenstellung beachten
  66. Time addDuration(int minutes){
  67. int q = this.timeInMinutesFromZero();
  68. int erg = q+minutes;
  69. Time t = timeInTimeFormat(erg);
  70. this.hour = t.hour;
  71. this.minutes = t.minutes;
  72. return this;
  73.  
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement