Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Calendar;
- import java.util.HashMap;
- /**
- *
- */
- public class Person
- {
- private String sn;
- private String fn;
- private int birth;
- private int death;
- private int getage;
- private int eventCounter;
- private Hending hending;
- private HashMap<Integer, Hending> lifeEvents;
- public Person(String sn, String fn, int birth, int death)
- {
- this.sn = sn;
- this.fn = fn;
- this.birth = birth;
- this.death = death;
- eventCounter = 1;
- getage = (death - birth);
- HashMap lifeEvents = new HashMap<Integer, Hending>();
- }
- public Person(String sn, String fn)
- {
- this.sn = sn;
- this.fn = fn;
- }
- public String getSn()
- {
- return this.sn;
- }
- public String getFn()
- {
- return this.fn;
- }
- public int getbirthyear()
- {
- return this.birth;
- }
- public int getdeathyear()
- {
- return this.death;
- }
- public int getage()
- {
- int age;
- if(birth == 0)
- {
- age = -1;
- }
- else if (death == 0)
- {
- Calendar now = Calendar.getInstance();
- int year = now.get(Calendar.YEAR);
- age = year - birth;
- }
- else
- {
- age = death - birth;
- }
- return age;
- }
- public void setbirth(int y)
- {
- birth = y;
- }
- public void setdeath(int y)
- {
- death = y;
- }
- public void print()
- {
- System.out.println("Name: " + sn + ", " + fn);
- System.out.println("Date of birth: " + birth);
- System.out.print((death > 0)? "Date of death: " + death + "\n": "");
- System.out.println("Age: " + getage());
- }
- public String toString()
- {
- String str = getFn() + " " + getSn() + " (" +
- getbirthyear() + " - " + getdeathyear() + ")";
- return str;
- }
- public void newLifeEvent(String lifeEvent, int year) {
- Hending nyHending = new Hending(lifeEvent, year);
- lifeEvents.put(1, nyHending);
- eventCounter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement