// Purpose: Set up some classes and interfaces for further questions.
// Style compromises were made to get this on one page.
// Author : Fred Swartz, 22 Feb 2006
////////////////////////////////////////////////////////////////////////// Human
public class Human {
private String name;
public Human(String name) { this.name = name; }
public String getName() { return name; }
@Override public String toString() { return "Human " + getName(); }
}
//////////////////////////////////////////////////////////////////// Electrician
interface Electrician { public String changeBulb(); }
//////////////////////////////////////////////////////////////////////// Plumber
interface Plumber { public String unplugDrain(); }
//////////////////////////////////////////////////////////////////// HandyPerson
class HandyPerson extends Human implements Electrician, Plumber {
public HandyPerson(String name) { super(name); }
public String changeBulb() { return "HP: Unscrew old, screw in new";}
public String unplugDrain(){ return "HP: Use plunger"; }
@Override public String toString() { return "HandyPerson " + getName(); }
}
////////////////////////////////////////////////////////////////// NobodySpecial
class NobodySpecial extends Human {
public NobodySpecial(String name) { super(name); }
public void changeBulb() {System.out.print("NS: Unscrew old, screw in new");}
public void unplugDrain() {System.out.println("NS: Use plunger"); }
@Override public String toString() { return "NobodySpecial " + getName(); }
}
////////////////////////////////////////////////////////////// IndustrialPlumber
class IndustrialPlumber extends Human implements Plumber {
public IndustrialPlumber(String name) { super(name); }
public String unplugDrain() {return "IP: We'll add it to our list.";}
}