/* lab3-6a.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 a radio show class Show { String name; ClockTime start; ClockTime finish; ILoAd ads; Show(String name, ClockTime start, ClockTime finish, ILoAd ads) { this.name = name; this.start = start; this.finish = finish; this.ads = ads; } } // to represent an ad within a radio show interface Ad{ } // to represent a commercial ad within a radio show class Commercial implements Ad { String name; int minutes; int profit; Commercial(String name, int minutes, int profit) { this.name = name; this.minutes = minutes; this.profit = profit; } } // to represent a service ad within a radio show class Service implements Ad { String name; int minutes; Service(String name, int minutes) { this.name = name; this.minutes = minutes; } } // Purpose: to represent an arbitrary number of ads. interface ILoAd {} // Purpose: to represent an empty list of ads. class MTLoAd implements ILoAd { // No fields // Constructor MTLoAd() {} } // Purpose: to represent a nonempty list of ads. class ConsLoAd implements ILoAd { Ad first; ILoAd rest; // Constructor ConsLoAd(Ad first, ILoAd rest) { this.first = first; this.rest = rest; } } // examples of the radio show class hierarchy 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); // (define ipod-ad (make-ad "ipod" 2 100)) Ad ipodAd = new Commercial("ipod", 2, 100); // (define ms-ad (make-ad "ms" 1 500)) Ad msAd = new Commercial("ms", 1, 500); // (define xbox-ad (make-ad "xbox" 2 300)) Ad xboxAd = new Commercial("xbox", 2, 300); // (define heart (make-service "heart-assoc" 1)) Ad heart = new Service("heart-assoc", 1); // (define youth (make-service "youth-prog" 2)) Ad youth = new Service("youth-prog", 2); // examples of lists of ads ILoAd noAds = new MTLoAd(); ILoAd newsAds = new ConsLoAd(this.ipodAd, new ConsLoAd(this.heart, new ConsLoAd(this.xboxAd, this.noAds))); ILoAd millionaireAds = new ConsLoAd(this.xboxAd, new ConsLoAd(this.youth, new ConsLoAd(this.ipodAd, new ConsLoAd(this.heart, new ConsLoAd(this.xboxAd, this.noAds))))); // examples of radio shows Show news = new Show("News", this.ct19hr00min, new ClockTime(19, 30), this.newsAds); Show millionaire = new Show("Millionaire", new ClockTime(10, 0), new ClockTime(11, 0), this.millionaireAds); } /* +------------------+ | Show | +------------------+ | String name | | ClockTime start |----+ | ClockTime finish |-+ | +--| ILoAd ads | | +------------------+ | | | | | | v v | +------------+ | | ClockTime | | +------------+ | | int hour | | | int minute | | +------------+ | | +------------+ +-->| ILoAd |<------+ +------------+ | / \ | --- | | | --------- | | | | +--------+ +------------+ | | MTLoAd | | ConsLoAd | | +--------+ +------------+ | +---| Ad first | | | | ILoAd rest |-+ | +------------+ v +-------------+ | Ad | +-------------+ / \ --- | ------------------- | | +-------------+ +-------------+ | Commercial | | Service | +-------------+ +-------------+ | String name | | String name | | int minutes | | int minutes | | int profit | +-------------+ +-------------+ */