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

Info icon This 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); // 1500 is number of pages & 52500 is number of definitions 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;} public String toString() {return (super.toString() + "\nNumber of definitions: " + definitions
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern