class Robot extends Object120 { String shape; boolean isTransformed; boolean isEvil; // N.B. `id` removed, for discussion of shallow/deep equality. // constructor -- call 'super' (voodoo!) Robot( String s, boolean t, boolean e ) { this.shape = s; this.isTransformed = t; this.isEvil = e; } /** Return a description of a Robot's current form. * @param bot The Robot to describe. * @return a description of a Robot's current form. */ String currentForm( ) { if (this.isTransformed) { return this.shape; } else { return "Tall 'bot"; } } static void testRobots() { Robot r1 = new Robot("Corvette", true, false); Robot r2 = new Robot("Mack Truck", false, true); testEqualStrings( r1.currentForm(), "Corvette" ); testEqualStrings( r2.currentForm(), "Tall 'bot" ); testEqualStrings( new Robot("phone", true, true).currentForm( ), "phone" ); testEqualBools( willBattle(r1, r2), false ); // more tests... testEqualRobots( evilCopy(r1), new Robot("Corvette",true,true) ); testEqualRobots( evilCopy(r2), r2 ); } /** 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!] */ static boolean willBattle( Robot bot1, Robot bot2 ) { return true; } /** Which of two robots is cooler? * @param bot1 The first Robot. * @param bot2 The second Robot. * @return Either bot1 or bot2, depening on who is cooler. * A robot with a *shorter* transformed-shape description is cooler; * in case of ties, the evil one is cooler. * */ /* static Robot coolerOf( Robot bot1, Robot bot2 ) { if ( length(bot1.shape) < length(bot2.shape) ) { ... } else { ... } } */ /** 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 the original's serial number but * with a '-E' concatenated; they are always evil; * they have the same disguise and transformation status. */ static Robot evilCopy( Robot aBot ) { return aBot; } /** If two booleans aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual boolean returned by a test call. * @param exp The expected boolean to be returned by a test call. */ static void testEqualBools(boolean act, boolean exp) { if (act==exp) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two Robots aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual Robot returned by a test call. * @param exp The expected Robot to be returned by a test call. */ static void testEqualRobots(Robot act, Robot exp) { if (equals(act,exp)) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } /** If two Strings aren't equal, print an error message. * Intended for use as a test-helper. * @param act The actual String returned by a test call. * @param exp The expected String to be returned by a test call. */ static void testEqualStrings(String act, String exp) { if (equals(act,exp)) { System.out.println("(test passed)"); } else { System.out.println( "Actual: " + act + "\nExpect: " + exp ); } } }