/* --- CSU213 Fall 2006 Lecture Notes --------- Copyright 2006 Viera K. Proulx Lecture 1: September 6, 2006 Part 3: Data definitions with containment in ProfessorJ Managing ITunes --------------- */ /* ;; A Song is (make-song String Artist Number Number) (define-struct song (title artist size price)) ;; An Artist is (make-artist String Number) (define-struct artist (name dob)) ;; Examples: (define beatles (make-artist "Beatles" 1964)) (define eagles (make-artist "Eagles" 1980)) (define help (make-song "Help" beatles 3178852 0.99)) (define hc (make-song "Hotel California" eagles 4405515 0.99)) */ /* +---------------+ | Song | +---------------+ | String title | | Artist artist |--+ | int size | | | double price | | +---------------+ | v +-------------+ | Artist | +-------------+ | String name | | int dob | +-------------+ */ // to represent an ITunes song recording class Song { String title; Artist artist; int size; double price; Song(String title, Artist artist, int size, double price) { this.title = title; this.artist = artist; this.size = size; this.price = price; } } // to represent an artist class Artist { String name; int dob; Artist(String name, int dob) { this.name = name; this.dob = dob; } } class ExamplesSong { ExamplesSong(){} Artist beatles = new Artist("Beatles", 1963); Artist eagles = new Artist("Eagles", 1972); Song help = new Song("help", this.beatles, 3178852, 0.99); Song hc = new Song("Hotel California", this.eagles, 4405515, 0.99); } // Playing a Game - crossing a minefield // ------------------------------------- /* ;; A Player is (make-player String Posn) (define-struct player (name position)) ;; A Mine is represented by a Posn ;; Examples: (define john (make-player "John" (make-posn 50 50))) (define mine1 (make-posn 20 50)) (define mine2 (make-posn 50 40)) ;; ... */ /* +-----------------+ | Player | +-----------------+ | String name | | CartPt position |--+ +-----------------+ | v +--------+ | CartPt | +--------+ | int x | | int y | +--------+ */ // to represent a player in a minefield crossing game class Player { String name; CartPt position; Player(String name, CartPt position) { this.name = name; this.position = position; } } /* +--------+ | CartPt | +--------+ | int x | | int y | +--------+ */ // to represent a Cartesian point class CartPt { int x; int y; CartPt(int x, int y) { this.x = x; this.y = y; } } class ExamplesMinefield{ ExamplesMinefield() {} Player john = new Player("John", new CartPt(50, 50)); CartPt mine1 = new CartPt(20, 50); CartPt mine2 = new CartPt(50, 40); } // Traveling on the T in Boston // ---------------------------- /* ;; A Station is (make-station (String String Number)) (define-struct station (name line price)) ;; Examples: (define harvard (make-station "Harvard" "red" 1.25)) (define riverside (make-station "Riverside" "green" 2.50)) (define kenmore (make-station "Kenmore" "green" 1.25)) */ // Leave this as is --- next time we add a list of lines, // for example the red and green line that go through the // Park station... /* +--------------+ | Station | +--------------+ | String name | | String line | | double price | +--------------+ */ // to represent a station on a Boston T class Station { String name; String line; double price; Station(String name, String line, double price) { this.name = name; this.line = line; this.price = price; } } class ExamplesStation{ ExamplesStation() {} Station harvard = new Station("Harvard","red", 1.25); Station riverside = new Station("Riverside", "green", 2.50); Station kenmore = new Station("Kenmore", "green", 1.25); }