c17f05t2 - CSE 17 Test 2 Tuesday 15 November 2005...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 17 Test 2 Tuesday 15 November 2005 >>>>>>>>>>>>>>>>>>>>>>>>>>>SUGGESTED ANSWERS<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 1. Design a class called Dictionary that is a subclass of the Book class. Create the methods in Dictionary so that word.main() produces the following output. Number of pages: 1500 Number of definitions: 52500 Defintions per page: 35.0 Note: 52500/1500 = 35.0 N public class Words { public static void main(String[] args) { Dictionary webster = new Dictionary(1500,52500); System.out.println(webster); System.out.println("Note: " + webster.getDefinitions() + "/" + webster.getPages() + " = " + webster.computeRatio()); } } class Book {protected int pages = 1500; public Book(int p) {pages = p;} public int getPages(){return pages;} public String toString(){return "Number of pages: "+ pages;} } <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< class Dictionary extends Book {private int definitions; public Dictionary (int p, int numDef){ super(p); definitions = numDef;} public double computeRatio(){return definitions/pages;} public int getDefinitions(){return definitions;}
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 3

c17f05t2 - CSE 17 Test 2 Tuesday 15 November 2005...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online