Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. import java.util.Calendar;
  2. import java.util.HashMap;
  3.  
  4. /**
  5.  *
  6.  */
  7. public class Person
  8. {
  9.     private String sn;
  10.     private String fn;
  11.     private int birth;
  12.     private int death;
  13.     private int getage;
  14.     private int eventCounter;
  15.     private Hending hending;
  16.     private HashMap<Integer, Hending> lifeEvents;
  17.    
  18.     public Person(String sn, String fn, int birth, int death)
  19.     {
  20.         this.sn = sn;
  21.         this.fn = fn;
  22.         this.birth = birth;
  23.         this.death = death;
  24.         eventCounter = 1;
  25.         getage = (death - birth);
  26.         HashMap lifeEvents = new HashMap<Integer, Hending>();
  27.     }
  28.    
  29.     public Person(String sn, String fn)
  30.     {
  31.         this.sn = sn;
  32.         this.fn = fn;
  33.     }
  34.    
  35.     public String getSn()
  36.     {
  37.         return this.sn;
  38.     }
  39.    
  40.     public String getFn()
  41.     {
  42.         return this.fn;
  43.     }
  44.    
  45.     public int getbirthyear()
  46.     {
  47.         return this.birth;
  48.     }
  49.    
  50.     public int getdeathyear()
  51.     {
  52.         return this.death;
  53.     }
  54.    
  55.     public int getage()
  56.     {
  57.         int age;
  58.         if(birth == 0)
  59.         {
  60.             age = -1;
  61.         }
  62.         else if (death == 0)
  63.         {
  64.             Calendar now = Calendar.getInstance();
  65.             int year = now.get(Calendar.YEAR);
  66.             age = year - birth;
  67.         }
  68.         else
  69.         {
  70.             age = death - birth;
  71.         }
  72.         return age;
  73.     }
  74.    
  75.     public void setbirth(int y)
  76.     {
  77.         birth = y;
  78.     }
  79.    
  80.     public void setdeath(int y)
  81.     {
  82.         death = y;
  83.     }
  84.    
  85.    
  86.    
  87.     public void print()
  88.     {
  89.         System.out.println("Name: " + sn + ", " + fn);
  90.         System.out.println("Date of birth: " + birth);
  91.         System.out.print((death > 0)? "Date of death: " + death + "\n": "");
  92.         System.out.println("Age: " + getage());
  93.     }
  94.    
  95.     public String toString()
  96.     {
  97.         String str = getFn() + " " + getSn() + " (" +
  98.                      getbirthyear() + " - " + getdeathyear() + ")";
  99.         return str;
  100.     }
  101.    
  102.     public void newLifeEvent(String lifeEvent, int year) {
  103.        
  104.         Hending nyHending = new Hending(lifeEvent, year);
  105.         lifeEvents.put(1, nyHending);
  106.         eventCounter++;
  107.        
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement