package de.javakurs;
/**
 * This class will improve human by some methods
 * defined by the object-class.
 * 
 * This methods are <em>equals(..)</em> and <em>toString()</em>.
 * 
 * Also, it will use the access modifiers mentioned by <em>Björn</em>.
 * 
 * @author mario
 */
public class Human {
	
	private String name;
	
	/**
	 * Define a custom constructor, taking the name of the human
	 * 
	 * @param name the name of the student
	 */
	public Human(String name) {
		// set the name attribute
		this.name = name;
	}

	/**
	 * This method will return a string representation
	 * of the human.
	 */
	@Override
	public String toString() {
		// create the string to be returned
		return "Human: \""+this.name+"\"";
	}
	
	/**
	 * This method will return true if the objects are identical. 
	 * Otherwise it will return false.
	 */
	@Override
	public boolean equals(Object obj) {
		// check for an empty object
		if( obj == null ) {
			// comparison is not possible
			return false;
		}
		
		// look if the object is of the same type as the current object
		if( obj instanceof Human ) {
			// convert the object to a master student
			Human other = (Human)obj;
			
			// check for equal variables
			return other.name.equals(this.name);
		} else {
			// not the same type so no equal objects
			return false;
		}
		
		// unreachable code
	}
}
