public void setPricenum pr price pr return public void setNumPagesnum pages

Public void setpricenum pr price pr return public

This preview shows page 15 - 19 out of 47 pages.

public void setPrice(num pr)price = prreturnpublic void setNumPages(num pages)numPages = pagesreturnpublic num getStockNum()return stockNumpublic string getAuthor()return author
Programming Logic and Design, 8eSolutions 11-16public string getTitle()return titlepublic num getPrice()return pricepublic num getNumPages()return numPagespublic void displayInfo()output “Book info”output “Stock Number: ”, stockNumoutput “Author: ”, authoroutput “Title: ”, titleoutput “Price: ”, priceoutput “Number of pages: ”, numPagesreturnendClassb. Design a class named TextBookthat is a child class of Book. Include a new data field for the grade level of the book. Override the Book class displayInfo() method to accommodate the new grade-level field.Answer: A sample solution followsDiagram:Book-stockNum: num-author: string-title: string-price: num-numPages: num+setStockNum(number : num) : void+setAuthor(au : string) : void+setTitle(ttl : string) : void+setPrice(pr : num) : void+setNumPages(pages : num) : void+getStockNum() : num+getAuthor() : string+getTitle() : string+getPrice() : num+getNumPages() : num+displayInfo() : voidTextBook-gradeLevel: num+setGradeLevel(level : num) : void+getGradeLevel() : num+displayInfo() : void
Programming Logic and Design, 8eSolutions 11-17Pseudocode:class TextBook inheritsFrom BookDeclarationsprivate num gradeLevelpublic void setGradeLevel(num level)gradeLevel = levelreturnpublic num getGradeLevel()return gradeLevelpublic void displayInfo()output “Book info”output “Stock Number: ”, getStockNum()output “Author: ”, getAuthor()output “Title: ”, getTitle()output “Price: ”, getPrice()output “Number of pages: ”, getNumPages()output “Grade Level: ”, gradeLevelreturnendClassc. Design an application that instantiates an object of each type and demonstrates all the methods.Answer: A sample solution followsPseudocode:startDeclarationsBook mysteryNovelBook historyBookmysteryNovel.setStockNum(1234)mysteryNovel.setAuthor(“Fred Jones”)mysteryNovel.setTitle(“The Missing Hat”)mysteryNovel.setPrice(4.95)mysteryNovel.setNumPages(431)historyBook.setStockNum(2314)historyBook.setAuthor(“Janet Smith”)historyBook.setTitle(“History of the USA”)historyBook.setPrice(79.99)historyBook.setNumPages(925)historyBook.setGradeLevel(5)output “Book 1 (mystery book) info:”output “Demonstrating get methods:”output mysteryNovel.getStockNum()output mysteryNovel.getAuthor()
Programming Logic and Design, 8eSolutions 11-18output mysteryNovel.getTitle()output mysteryNovel.getPrice()output mysteryNovel.getNumPages()output “Demonstrating displayInfo() method:”mysteryNovel.displayInfo()output “Book 2 (history book) info:”output “Demonstrating get methods:”output historyBook.getStockNum()output historyBook.getAuthor()output historyBook.getTitle()output historyBook.getPrice()output historyBook.getNumPages()output historyBook.getGradeLevel()output “Demonstrating displayInfo() method:”historyBook.displayInfo()stop7.Complete the following tasks:a. Design a class named Player

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture