// purpose: represent a cupcake. also known as faery cakes as their size is // appropriate for faeries and their kin ( e.g., leprechauns ) public class Cupcake { public static void main( String[] args ) { Cupcake c1 = new Cupcake( Flavor.CHOCOLATE, Flavor.VANILLA, false ); Cupcake c2 = new Cupcake( Flavor.VANILLA, Flavor.VANILLA, true ); System.out.println( c1 ); System.out.println( c2 ); } // attributes Flavor cake; Flavor icing; boolean sprinkled; // default constructor public Cupcake() { this.setCake( Flavor.VANILLA ); this.setIcing( Flavor.CHOCOLATE ); this.setSprinkled( false ); } // specific constructor public Cupcake( Flavor c, Flavor i, boolean s ) { this.setCake( c ); this.setIcing( i ); this.setSprinkled( s ); } // toString(): get a String representation public String toString() { String representation = "Cupcake(" + this.getCake() + ", " + this.getIcing() + ", " + this.isSprinkled() + ")"; return representation; } // mutators -- changes of attributes public void setCake( Flavor f ) { this.cake = f; } public void setIcing( Flavor f ) { this.icing = f; } public void setSprinkled( boolean b ) { this.sprinkled = b; } // inspectors -- describers of attributes public Flavor getCake() { return this.cake; } public Flavor getIcing() { return this.icing; } public boolean isSprinkled() { return this.sprinkled; } // equals public boolean equals( Object c ) { if ( c instanceof Cupcake ) { Cupcake that = (Cupcake) c; Flavor c1 = this.getCake(); Flavor c2 = that.getCake(); Flavor i1 = this.getIcing(); Flavor i2 = that.getIcing(); boolean b1 = this.isSprinkled(); boolean b2 = that.isSprinkled(); boolean comparison = c1.equals( c2 ) && i1.equals( i2 ) && ( b1 == b2); return comparison; } else { return false; } } }