Design a class named Book that holds a stock number, author, title, price, and number of pages for a book. Include a method that sets all the data files and another that prints the values for each data field. Create the class diagram and write the pseudocode that defines the class.
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 methods that set and print the data so that you accommodate the new grade-level field. Create the class diagram and write the pseudocode that defines the class.
2 answers
Very basic pseudo code is what we're dealing with. New to OOP and I do not understand it. I'm not asking anyone to simply solve these problems but rather help walking me through them if possible. These are not assignments, just exercises from the book that I'm trying to do on my own time.
class Book
// Declarations
private num stockNumber
private num price
private num bookPageNum
private string author
private string title
//Methods to set the values.
public void setStockNumber(num stockNumber)
this.stockNumber = stockNumber
return
public void setPrice(num price)
this.price = price
return
public void setBookPageNum(num bookPageNum)
this.bookPageNum = bookPageNum
return
public void setAuthor(string author)
this.author = author
return
public void setTitle(string title)
this.title = title
return
//Methods to get the values.
public num getStockNumber()
return stockNumber
public num getPrice()
return price
public num getBookPageNum()
return bookPageNum
public string getAuthor()
return author
public string getTitle()
return title
endClass
// Declarations
private num stockNumber
private num price
private num bookPageNum
private string author
private string title
//Methods to set the values.
public void setStockNumber(num stockNumber)
this.stockNumber = stockNumber
return
public void setPrice(num price)
this.price = price
return
public void setBookPageNum(num bookPageNum)
this.bookPageNum = bookPageNum
return
public void setAuthor(string author)
this.author = author
return
public void setTitle(string title)
this.title = title
return
//Methods to get the values.
public num getStockNumber()
return stockNumber
public num getPrice()
return price
public num getBookPageNum()
return bookPageNum
public string getAuthor()
return author
public string getTitle()
return title
endClass