Mahmoud_Hawara

PA08 - 3

Jan 13th, 2026
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. public class Time {
  2.     int hours;
  3.     int minutes;
  4.     int seconds;
  5.    
  6.     public Time() {
  7.         hours = 0;
  8.         minutes = 0;
  9.         seconds = 0;
  10.     }
  11.    
  12.     public Time(int hours, int minutes, int seconds) {
  13.         this.hours = hours;
  14.         this.minutes = minutes;
  15.         this.seconds = seconds;
  16.     }
  17.    
  18.     public int hours() {
  19.         return hours;
  20.     }
  21.    
  22.     public int minutes() {
  23.         return minutes;
  24.     }
  25.    
  26.     public int seconds() {
  27.         return seconds;
  28.     }
  29.    
  30.     public void addminute() {
  31.         minutes++;
  32.         if (minutes == 60) {
  33.             hours++;
  34.             minutes = 0;
  35.         }
  36.     }
  37.    
  38.     public void addseconds() {
  39.         seconds++;
  40.         if (seconds == 60) {
  41.             minutes++;
  42.             seconds = 0;
  43.         }
  44.     }
  45.    
  46.     public void addhour() {
  47.         hours++;
  48.     }
  49.    
  50.     public String toString() {
  51.         return hours + ":" + minutes + ":" + seconds;
  52.     }
  53.    
  54.     public static void main(String[] args) {
  55.         Time t = new Time(5, 3, 0);
  56.         System.out.println(t);
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment