// Lecture 3 // CS U213 Fall 2008 // mobile-data.java /* Sample mobiles: --------------- Simple mobile | | 10 blue Complex mobile | | | ------------+----- | | ------+------ | | | | 10 | 40 red 10 green blue */ import draw.*; import geometry.*; import colors.*; /* +---------+ | IMobile |<---------------+ +---------+ | +---------+ | | | / \ | --- | | | --------------------- | | | | +--------------+ +---------------+ | | Simple | | Complex | | +--------------+ +---------------+ | | int length | | int length | | | int weight | | int leftside | | | IColor color | | int rightside | | +--------------+ | IMobile left |----+ | IMobile right |----+ +---------------+ */ // to represent a mobile interface IMobile {} // to represent an item hanging at the end of a mobile class Simple implements IMobile { int length; int weight; IColor color; Simple(int length, int weight, IColor color) { this.length = length; this.weight = weight; this.color = color; } } // to represent a part of support structure for a mobile class Complex implements IMobile { int length; int leftSide; int rightSide; IMobile left; IMobile right; Complex(int length, int leftSide, int rightSide, IMobile left, IMobile right) { this.length = length; this.leftSide = leftSide; this.rightSide = rightSide; this.left = left; this.right = right; } } /* Sample mobiles: --------------- simple1: | | 10 blue complex2 (with complex1 on the left and simple2 on the right) complex1 (with simple3 on the left, simple1 on the right) | | | ------------+----- | | ------+------ | | | | 10 | 40 red 10 green blue */ class Examples { Examples(){} IMobile simple1 = new Simple(20, 10, new Blue()); IMobile simple2 = new Simple(30, 40, new Green()); IMobile simple3 = new Simple(10, 10, new Red()); IMobile complex1 = new Complex(10, 5, 5, this.simple3, this.simple1); IMobile complex2 = new Complex(30, 10, 5, this.simple2, this.complex1); }