// datatype definition: record Book( String title, String author, int numPages, boolean isCopyrighted ) { static void testBasics() { Book cih = new Book( "The Cat in the Hat", "Dr Seuss", 37, true ); System.out.printf( "I just read %s and it was awesome.\n", new Book( "The Soul of Wit", "anonymous", 0, false ).toString() ); assert cih.numPages == 37; // won't compile, since records are immutable: // cih.numPages = 50; } /* Template: ** @return ...something related to `this` Book *_/ void templateForBook( /* Book this *_/ ) { return ...( this.title , this.author , this.numPages , this.isCopyrighted ); } */ static void testEnbiggen() { assert new Book( "Soul of Wit", "Barland", 0, false ).enbiggen().equals( new Book( "Soul of Wit", "Barland", 0, false )); Book cih = new Book( "The Cat in the Hat", "Dr Seuss", 37, true ); assert cih.enbiggen().equals( new Book( "The Cat in the Hat", "Dr Seuss", 74, true )); } /** @return a book like `this` but with bigger font (more pages) */ Book enbiggen( /* Book this */ ) { return new Book( this.title, this.author, 2*this.numPages, this.isCopyrighted ); } public static void main(String... __) { testBasics(); testEnbiggen(); } }