public class Robot { private String shape; private boolean isTransformed; private boolean isEvil; private String id; /** Constructor. * @param _id this robot's ID. * @param _shape this Robot's shape (when transformed). * @param _isTransformed Whether or not this Robot is currently transformed. * @param _isEvil Whether or not this Robot is evil. */ public Robot( String _id, String _shape, boolean _isTransformed, boolean _isEvil ) { this.id = _id; this.shape = _shape; this.isTransformed = _isTransformed; this.isEvil = _isEvil; } /** Return whether or not this robot is evil. * @return whether or not this robot is evil. */ public boolean getIsEvil() { return this.isEvil; } /** Return a description of a Robot's current form. * @param bot The Robot to describe. * @return a description of a Robot's current form. */ public String currentForm( ) { if (this.isTransformed) { return this.shape; } else { return "Tall 'bot"; } } /** Will one robot initiate battle w/ a second, given the chance? * @param bot1 The first Robot. * @param bot2 The second Robot. * @return true iff `bot1` will initiate a battle with `bot2`. * bot1 will initiate a battle if bot1 is evil * and bot2 is good+non-transformed. * [Alternate: two evil robots battle as well!] */ public boolean willBattle( /* Robot this, */ Robot that ) { /* Inventory: * this.isEvil (boolean) * bot2.isTransformed (boolean) && || ! == if-else * bot2.isEvil */ return this.isEvil && !that.isTransformed && !that.isEvil; } /** Which of two robots is cooler? * @param bot1 The first Robot. * @param bot2 The second Robot. * @return Either bot1 or bot2, depending on who is cooler. * A robot with a *shorter* transformed-shape description is cooler; * in case of ties, the evil one is cooler. * */ public static Robot coolerOf( Robot bot1, Robot bot2 ) { if ( bot1.shape.length() < bot2.shape.length() ) { return bot1; } else { return bot2; } } /** Make a new, evil copy of a given Robot. * @param aBot The Robot to make an evil copy of. * @return a new, evil copy of `aBot`. * (Evil copies have are always evil; * they have the same disguise and transformation status. */ public Robot evilCopy( /* Robot this */ ) { return new Robot( this.id, this.shape, this.isTransformed, true ); } public boolean equals( Robot that ) { return (this.isEvil == that.isEvil) && (this.isTransformed == that.isTransformed) && (this.shape.equals(that.shape)) && (this.id.equals(that.id)); } }