/* Thursday am lecture - Part 4: +--------+ | LoBook |<--------------+ +--------+ | +--------+ | | | / \ | --- | | | ------------------- | | | | +----------+ +-------------+ | | MTLoBook | | ConsLoBook | | +----------+ +-------------+ | +----------+ +-| Book first | | | | LoBook rest |-+ | | +-------------+ | | | | | v +--+ +---------------+ | Book | +---------------+ | String title | | String author | | Num cnum | +---------------+ */ // to represent a book in a library class Book{ String title; String author; int cnum; Book(String title, String author, int cnum){ this.title = title; this.author = author; this.cnum = cnum; } } // to represent a list of books interface LoBook { } // to represent an empty list of books class MTLoBook implements LoBook { MTLoBook() { } } // to represent a nonempty list of books class ConsLoBook implements LoBook { Book first; LoBook rest; ConsLoBook(Book first, LoBook rest) { this.first = first; this.rest = rest; } } // client class for a list of books class Examples3{ Examples3(){} Book ch = new Book("Cat in a Hat", "Dr Seuss", 777); Book alice = new Book("Alice's Adventures in Wonderland", "Lewis Carroll", 234); Book geh = new Book("Green Eggs and Ham", "Dr Seuss", 779); LoBook mtbks = new MTLoBook(); LoBook lobks1 = new ConsLoBook(this.ch, this.mtbks); LoBook lobks2 = new ConsLoBook(this.alice, this.lobks1); LoBook lobks3 = new ConsLoBook(this.geh, this.lobks2); }