class Lunchbox { Sandwich mainCourse; Beverage drink; Cake dessert; Lunchbox( Sandwich mainCourse, Beverage drink, Cake dessert ) { this.mainCourse = mainCourse; this.drink = drink; this.dessert = dessert; } // new Lunchbox(new Sandwich("rye",false), new Beverage("Lime",true),new Cake("Choco",2,"Choco")).sameAs( // new Lunchbox(new Sandwich("rye",false), new Beverage("Lime",true),new Cake("Choco",2,"Choco")) // == true // new Lunchbox(new Sandwich("rye",false), new Beverage("Lime",true),new Cake("Choco",2,"Choco")).sameAs( // new Lunchbox(new Sandwich("rye",false), new Beverage("Lemon",true),new Cake("Choco",2,"Choco")) // == false // To determine if this Lunchbox is the same as l boolean sameAs( Lunchbox l ) { // ... this.mainCourse.SandwichMethod() ... this.drink.BeverageMethod() ... this.dessert.CakeMethod() // ... l.mainCousre... return this.mainCourse.sameAs( l.mainCourse ) && this.drink.sameAs( l.drink ) && this.dessert.sameAs( l.dessert ); } // To determine if this Lunchbox is the same as l boolean equals( Object l ) { // ... this.mainCourse.SandwichMethod() ... this.drink.BeverageMethod() ... this.dessert.CakeMethod() // ... l return this.sameAs((Lunchbox) l); } } class Sandwich { String bread; boolean pbAndJ; Sandwich( String bread, boolean pbAndJ ) { this.bread = bread; this.pbAndJ = pbAndJ; } // new Sandwich( "white", true ).sameAs( new Sandwich("white",false) ) == false // new Sandwich( "wheat", false ).sameAs( new Sandwich("wheat", false) ) == true // To determine if this Sandwich is the same as s boolean sameAs( Sandwich s ) { // this.bread ... this.pbAndJ ... s ... return this.bread.equals(s.bread) && (this.pbAndJ == s.pbAndJ); } } class Beverage { String flavor; boolean carbonated; Beverage( String flavor, boolean carbonated ) { this.flavor = flavor; this.carbonated = carbonated; } //new Beverage("orange",false).sameAs( new Beverage("orange",false)) == true //new Beverage("orange",false).sameAs( new Beverage("orange",true)) == false //To determine if this Beverage is the same as b boolean sameAs( Beverage b ) { // ... this.flavor ... this.carbonated ... b return this.flavor.equals(b.flavor) && (this.carbonated == b.carbonated); } } class Cake { String icing, base; int layers; Cake( String icing, int layers, String base ) { this.icing = icing; this.layers = layers; this.base = base; } // To determine if this Cake is like c boolean sameAs( Cake c ) { // ... this.icing ... this.layers ... this.base ... return this.icing.equals(c.icing) && this.layers == c.layers && this.base.equals(c.base); } }