;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname lecture3-data) (read-case-sensitive #t) (teachpacks ((lib "world.ss" "teachpack" "htdp") (lib "testing.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "world.ss" "teachpack" "htdp") (lib "testing.ss" "teachpack" "htdp"))))) ;; TSRJ 2008 - Advanced ;; Lecture 3: Data Definitions - Part 1 ;; Data Definitions in Scheme ;; --------------------------- ;; ;; Plane Flight ;; ------------ ;; ;; To represent a plane trip ;; ;; A Flight is (make-flight String String Number Number) ;; interpretation: (make-flight o d p s) creates a Flight with ;; o as the origin airport, ;; d as the destination airport, ;; p as the price of the flight and ;; s as the seat number. (define-struct flight (departure arrival cost seat)) ;; Examples: ;; --------- (make-flight "Logan" "JFK" 80 21) ;; Songs in Albums ;; --------------- ;; ;; To represent a song in an album ;; ;; A Song is (make-song String String String String) ;; interpretation: (make-song t a b g) creates a song with ;; t as the song title ;; a as the artist name ;; b as the album name ;; g as the song's genre (define-struct song (title artist album genre)) ;; Examples: ;; -------- (make-song "Paint it Black" "The Rolling Stones" "Aftermath" "Rock") ;; Tivo Programs ;; ------------- ;; ;; To represent a recording of a show using Tivo. ;; ;; A Show is (make-show String Number Number Number) ;; interpretation: (make-show n c t d) creates a recording for a show with ;; n as the name of the show ;; c as the channel's number ;; t as the time the show starts ;; d as the duration of the show (define-struct show (name channel time duration)) ;; Examples: ;; -------- (define mwc (make-show "Married With Children" 25 2100 1)) ;; Scheme functions to work with our data definitions ;; -------------------------------------------------- (show-name mwc) ;; "Married With Children" (show-channel mwc) ;; 25 (show-time mwc) ;; 2100 (show-duration mwc) ;; 1 (show? mwc) ;; true ;; The above should be a refresher on data definitions and scheme. ;; How do we go about doing the same thing in Java? ;; NOTE: To start a one-line comment in Java we use '//' ;; Up till now you can run the given code using the Beginner HtDP language. ;; The rest of these notes run in ProfessorJ Begginer Language.