Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.95 KB | None | 0 0
  1.  
  2. public class Oseba {
  3.    
  4.     String ime;
  5.     String priimek;
  6.     char spol;
  7.     int letoRojstva;
  8.     Oseba oce;
  9.     Oseba mati;
  10.    
  11.     public Oseba(String ime, String priimek, char spol, int letoRojstva) {
  12.         this.ime = ime;
  13.         this.priimek = priimek;
  14.         this.spol = spol;
  15.         this.letoRojstva = letoRojstva;
  16.     }
  17.     public String vrniIme() {
  18.         return ime;
  19.     }
  20.     public void nastaviIme(String novoIme) {
  21.         this.ime = novoIme;
  22.     }
  23.     public String toString() {
  24.         System.out.printf("%s %s (%c), %d", ime, priimek, spol, letoRojstva);
  25.         return "";
  26.     }
  27.     public int starost(int leto) {
  28.         return leto - letoRojstva;
  29.     }
  30.     public boolean jeStarejsaOd(Oseba os) {
  31.         if (this.letoRojstva < os.letoRojstva) {
  32.             return true;
  33.         }
  34.         return false;
  35.     }
  36.     public Oseba(String ime, String priimek, char spol, int letoRojstva, Oseba oce, Oseba mati) {
  37.         this.ime = ime;
  38.         this.priimek = priimek;
  39.         this.spol = spol;
  40.         this.letoRojstva = letoRojstva;
  41.         this.oce = oce;
  42.         this.mati = mati;
  43.     }
  44.     public String imeOceta() {
  45.         if (oce.ime == null) {
  46.             return oce.ime;
  47.         }
  48.         return null;
  49.     }
  50. }
  51.  
  52.  
  53. public class Test05 {
  54.  
  55.     public static void main(String[] args) {
  56.         Oseba os11 = new Oseba("Jozhef",  "Pogachnik", 'M', 1921);
  57.         Oseba os12 = new Oseba("Marija",  "Pogachnik", 'Z', 1928);
  58.         Oseba os13 = new Oseba("France",  "Kotnik",    'M', 1932);
  59.         Oseba os14 = new Oseba("Ivana",   "Kotnik",    'Z', 1931);
  60.         Oseba os15 = new Oseba("Anton",   "Zajc",      'M', 1922);
  61.         Oseba os21 = new Oseba("Marjan",  "Pogachnik", 'M', 1946, os11, os12);
  62.         Oseba os22 = new Oseba("Dana",    "Pogachnik", 'Z', 1950);
  63.         Oseba os23 = new Oseba("Milan",   "Smole",     'M', 1953);
  64.         Oseba os24 = new Oseba("Metka",   "Smole",     'Z', 1953);
  65.         Oseba os25 = new Oseba("Zvone",   "Kotnik",    'M', 1956, os13, os14);
  66.         Oseba os26 = new Oseba("Tanja",   "Kotnik",    'Z', 1954);
  67.         Oseba os27 = new Oseba("Branka",  "Zajc",      'Z', 1952, os15, os14);
  68.         Oseba os31 = new Oseba("Dejan",   "Pogachnik", 'M', 1973, os21, os22);
  69.         Oseba os32 = new Oseba("Mojca",   "Pogachnik", 'Z', 1977, os23, os24);
  70.         Oseba os33 = new Oseba("Miha",    "Smole",     'M', 1978, os23, os24);
  71.         Oseba os34 = new Oseba("Nezha",   "Smole",     'Z', 1980, os25, os26);
  72.         Oseba os35 = new Oseba("Alesh",   "Kotnik",    'M', 1982, os25, os26);
  73.         Oseba os36 = new Oseba("Jana",    "Kotnik",    'Z', 1981);
  74.         Oseba os41 = new Oseba("Rok",     "Pogachnik", 'M', 2003, os31, os32);
  75.         Oseba os42 = new Oseba("Eva",     "Pogachnik", 'Z', 2006, os31, os32);
  76.         Oseba os43 = new Oseba("Gal",     "Smole",     'M', 2009, os33, os34);
  77.         Oseba os44 = new Oseba("Maj",     "Kotnik",    'M', 2010, os35, os36);
  78.         Oseba os45 = new Oseba("Nika",    "Kotnik",    'Z', 2012, os35, os36);
  79.  
  80.         System.out.println(os32.imeOceta());
  81.         System.out.println(os27.imeOceta());
  82.         System.out.println(os14.imeOceta());
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement