Advertisement
blackpab

Java Zestaw 5 - zadanie 2

Apr 3rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package data;
  2.  
  3. public class Data {
  4.     int r,m,d;
  5.  
  6.     public Data(int r, int m, int d) {
  7.         this.r = r;
  8.         this.m = m;
  9.         this.d = d;
  10.     }
  11.  
  12.     public Data(int r, int m) {
  13.         this(r,m,1);
  14.     }
  15.  
  16.     public Data(int r) {
  17.         this(r, 1, 1);
  18.     }
  19.  
  20.     public Data() {
  21.         this(2000, 1, 1);
  22.     }
  23.    
  24.     @Override
  25.     public String toString() {
  26.         return String.format("%04d-%02d-%02d", r, m, d);
  27.     }
  28.    
  29.    
  30.     public static void main(String[] args) {      
  31.         Data d1 = new Data();
  32.         System.out.println(d1);
  33.        
  34.         DataICzas dt1 = new DataICzas(2017, 4, 3, 13, 0, 1);
  35.         System.out.println(dt1);
  36.        
  37.         DataICzas dt2 = new DataICzas(1, 12, 14);
  38.         System.out.println(dt2);
  39.     }        
  40. }
  41.  
  42.  
  43. // -------------------------------------------------------------------------------
  44.  
  45. package data;
  46.  
  47. public class DataICzas extends Data {
  48.  
  49.     int g, mi, s;
  50.  
  51.     public DataICzas(int r, int m, int d, int g, int mi, int s) {
  52.         super(r, m, d); //jawne odwolanie sie do konstruktora klasy bazowej
  53.         this.g = g;
  54.         this.mi = mi;
  55.         this.s = s;
  56.     }
  57.  
  58.     public DataICzas(int r, int m, int d, int g, int mi) {
  59.         this(r, m, d, g, mi, 0);
  60.     }
  61.  
  62.     public DataICzas(int r, int m, int d, int g) {
  63.         this(r, m, d, g, 0, 0);
  64.     }
  65.  
  66.     public DataICzas(int r, int m, int d) {
  67.         this(r, m, d, 0, 0, 0);
  68.     }
  69.  
  70.     @Override
  71.     public String toString() {
  72.         return String.format("%04d-%02d-%04d %02d:%02d:%02d ", r, m, d, g, mi, s);
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement