Demo entry 6344383

Person

   

Submitted by Garnet Yeates on Jan 11, 2017 at 22:01
Language: Java. Code size: 1.8 kB.

package com.gmail.garnetyeates.operationexecutor;

import java.util.List;
import java.util.ArrayList;
import java.util.GregorianCalendar;

public class Person {
	
	private static ArrayList<Person> people = new ArrayList<>();
	
	private String firstName;
	private String lastName;
	private int age;
	private GregorianCalendar birthDate;
	private HairColor hairColor;

	public Person(String firstName, String lastName, GregorianCalendar birthDate, HairColor hairColor) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.birthDate = birthDate;
		this.hairColor = hairColor;
		people.add(this);
	}
	
	public static List<Person> listPeople() {
		ArrayList<Person> clone = new ArrayList<>();
		for (Person p : people) clone.add(p);
		return clone;
	}
	
	public String getFullname() {
		return firstName + " " + lastName;
	}
	
	public String getFirstName() {
		return firstName;
	}
	
	public String getLastName() {
		return lastName;
	}

	public int getAge() {
		return age;
	}
	
	public void kill() {
		people.remove(this);
	}
	
	public GregorianCalendar getBirthDate() {
		if (birthDate.clone() instanceof GregorianCalendar) return (GregorianCalendar) birthDate.clone();
		else return null;
	}
	
	public String getStatistics() {
		String mm = (birthDate.get(GregorianCalendar.MONTH) + 1) + "";
		String dd = birthDate.get(GregorianCalendar.DAY_OF_MONTH) + "";
		String yy = birthDate.get(GregorianCalendar.YEAR) + "";
		
		if (Integer.parseInt(mm) < 10) mm = "0" + mm;
		if (Integer.parseInt(dd) < 10) dd = "0" + dd;
		
		return "['" + this.getFullname() + "', Born " + mm + "/" + dd + "/" + yy + ", " + hairColor.toString().toLowerCase() + " hair]";
	}
	
	public HairColor getHairColor() {
		return hairColor;
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).