/* lab3-6b.java */ // to represent the time of day class ClockTime { int hour; int minute; ClockTime(int hour, int minute) { this.hour = hour; this.minute = minute; } } // to represent an entry in an iPhoto collection interface Shot{ } // to represent a still photo in an iPhoto collection class Photo implements Shot{ String name; int width; int height; int bytes; String kind; ClockTime time; Photo(String name, int width, int height, int bytes, String kind, ClockTime time){ this.name = name; this.width = width; this.height = height; this.bytes = bytes; this.kind = kind; this.time = time; } } // to represent a video clip in an iPhoto collection class Video implements Shot{ String name; String kind; int size; int duration; // in minutes boolean sound; ClockTime time; Video(String name, String kind, int size, int duration, boolean sound, ClockTime time){ this.name = name; this.kind = kind; this.size = size; this.duration = duration; this.sound = sound; this.time = time; } } // Purpose: to represent an arbitrary number of ads. interface ILoShot {} // Purpose: to represent an empty list of ads. class MTLoShot implements ILoShot { // No fields // Constructor MTLoShot() {} } // Purpose: to represent a nonempty list of ads. class ConsLoShot implements ILoShot { Shot first; ILoShot rest; // Constructor ConsLoShot(Shot first, ILoShot rest) { this.first = first; this.rest = rest; } } // examples for the class hierachy that represents photo and video shots class Examples{ Examples (){} // Examples for the class ClockTime ClockTime ct08hr15min = new ClockTime( 8, 15); ClockTime ct16hr35min = new ClockTime(16, 35); ClockTime ct09hr50min = new ClockTime( 9, 50); ClockTime ct19hr00min = new ClockTime(19, 0); // River photo w=3456 h=2304 3614571 bytes "jpeg" at 8;15 am Shot river = new Photo("River", 3456, 2304, 3614571, "jpeg", this.ct08hr15min); // Mountain photo w=2448 h=3264 1276114 bytes "jpeg" at 7:00 pm (sunset) Shot mountain = new Photo("Mountain", 2448, 3264, 1276114, "jpeg", this.ct19hr00min); // People photo w=545 h=641 13760 bytes "gif" at 4:35 pm (party) Shot people = new Photo("People", 545, 641, 13760, "gif", this.ct16hr35min); // PLT icon image w=16 h=16 1334 bytes "bmp" at 9:50 am Shot pltIcon = new Photo("PLT icon", 16, 16, 1334, "bmp", this.ct09hr50min); // Beach video "QuickTime" 3614571 bytes 5 min silent at 4:35 pm Shot beach = new Video("Beach", "QuickTime", 3614571, 5, false, this.ct16hr35min); // Hike video "RealPlayer" 1276114 bytes 3 min silent at 9:50 am Shot hike = new Video("Hike", "RealPlayer", 1276114, 3, false, this.ct09hr50min); // Party video "QuickTime" 5456434bytes 2 min with sound at 7:00 pm Shot party = new Video("Party", "QuickTime", 5456434, 2, true, this.ct19hr00min); // Tutorial video "RealPlayer" 23551334 bytes 5 min at 9:50 am Shot tutorial = new Video("Tutorial", "RealPlayer", 23551334, 5, true, this.ct09hr50min); // an empty list of shots ILoShot noShots = new MTLoShot(); // personal still photos ILoShot photos = new ConsLoShot(this.river, new ConsLoShot(this.mountain, new ConsLoShot(this.people, this.noShots))); // photos and videos from outdoor trips ILoShot trips = new ConsLoShot(this.river, new ConsLoShot(this.mountain, new ConsLoShot(this.beach, new ConsLoShot(this.hike, this.noShots)))); } /* +------------+ | ILoShot |<------+ +------------+ | / \ | --- | | | --------- | | | | +----------+ +--------------+ | | MTLoShot | | ConsLoShot | | +----------+ +--------------+ | +--| Shot first | | | | ILoShot rest |-+ | +--------------+ v +------------+ | Shot | +------------+ / \ --- | ------------------------- | | +----------------+ +----------------+ | Photo | | Video | +----------------+ +----------------+ | String name | | String name | | int width | | String kind | | int height | | int size | | int bytes | | int duration | | String kind | | boolean sound | | ClockTime time |--+ +--| ClockTime time | +----------------+ | | +----------------+ v v +------------+ | ClockTime | +------------+ | int hour | | int minute | +------------+ */