/*********************************************** * CS2510 Spring 2011 * Lecture #14.1 * Circular Data ***********************************************/ import tester.*; // Represents a Movie class Movie{ String title; Actor star; Movie(String title, Actor star){ this.title = title; this.star = star; // Give the star a role in this movie this.star.setRole(this); } // Is this movie the same as the given movie? boolean sameMovie(Movie that){ return (this.title.equals(that.title)); } } // Represents a(n) Actor class Actor{ String name; Movie role; Actor(String name){ this.name = name; } // Set the Movie Role for this Actor void setRole(Movie m){ this.role = m; } // Is this actor the same as the given actor? boolean sameActor(Actor that){ return (this.name.equals(that.name) && this.role.sameMovie(that.role)); } } // Examples... Tests class LectureExamples{ Actor bryan; Actor spencer; Movie mine; Movie sd_spy; LectureExamples(){ this.resetData(); } // Setup our testing data void resetData(){ this.bryan = new Actor("Bryan"); this.spencer = new Actor("Spencer"); // The cycle is fixed in the Movie constructor... this.mine = new Movie("Minecraft: the Movie", this.bryan); this.sd_spy = new Movie("The Spy Who ##*%&$", this.spencer); } // Test our cycles... boolean testWhat(Tester t){ this.resetData(); return (t.checkExpect(this.bryan.role, this.mine) && t.checkExpect(this.mine.star, this.bryan) && t.checkExpect(this.spencer.role, this.sd_spy) && t.checkExpect(this.sd_spy.star, this.spencer)); } }