Complete the following tasks a Design a class named Book that holds a stock

Complete the following tasks a design a class named

This preview shows page 23 - 29 out of 36 pages.

6.Complete the following tasks:a. Design a class named Book that holds a stock number, author, title, price, and number of pages. Include methods to set and get the values for each data field. Also include a displayInfo()method that displays each of the Book’s data fields with explanations.
COM 204 Assignment 7 +getStockNum() : num +getAuthor() : string +getTitle() : string +getPrice() : num +getNumPages() : num +displayInfo() : void Pseudocode: class Book Declarations private num stockNum private string author private string title private num price private num numPages public void setStockNum(num number) stockNum = number return public void setAuthor(string au) author = au return public void setTitle(string ttl) title = ttl return public void setPrice(num pr) 24
COM 204 Assignment 7 price = pr return public void setNumPages(num pages) numPages = pages return public num getStockNum() return stockNum public string getAuthor() return author public string getTitle() return title public num getPrice() return price public num getNumPages() return numPages public void displayInfo() output “Book info” output “Stock Number: ”, stockNum output “Author: ”, author output “Title: ”, title output “Price: ”, price output “Number of pages: ”, numPages return endClass 25
COM 204 Assignment 7 b. Design a class named TextBook that 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. Diagram: 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() : void TextBook -gradeLevel: num +setGradeLevel(level : num) : void +getGradeLevel() : num +displayInfo() : void 26
COM 204 Assignment 7 Pseudocode: class TextBook inheritsFrom Book Declarations private num gradeLevel public void setGradeLevel(num level) gradeLevel = level return public num getGradeLevel() return gradeLevel public 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: ”, gradeLevel return endClass c. Design an application that instantiates an object of each type and demonstrates all the methods. Pseudocode: start Declarations Book mysteryNovel 27
COM 204 Assignment 7 Book historyBook mysteryNovel.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:”

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture