Start declarations num size 100 book bookssize num

This preview shows page 26 - 30 out of 266 pages.

start Declarations num SIZE = 100 Book books[SIZE] num sub sub = 0 while sub < SIZE books[sub] = getBookValues() sub = sub + 1 1. A file named MAINTENANCE10-01.txt is included with your downloadable student files. A Answer :
endwhile displayBooks(books, SIZE) stop public static Book getBookValues() Declarations Book book string title num pages num price num MIN_PAGES = 200 num HIGH_PRICE = 0.10 num LOW_PRICE = 0.08 output "Enter title … " input title output "Enter pages … " input pages book.setTitle(title) book.setPages(pages) if pages <= MIN_PAGES then price = pages * HIGH_PRICE else price = MIN_PAGES * HIGH_PRICE + (pages – MIN_PAGES) * LOW_PRICE endif book.setPrice(price) return item public static void displayBooks(Book[] books, num SIZE) Declarations int x x = 0 while x < SIZE output "Title: ", books[x].getTitle() output "Pages: ", books[x].getPages() output "Price: ", books[x].getPrice() x = x + 1 endwhile return class Book Declarations private string title private num pages private num price public void setTitle(string bookTitle) title = booktitle
return public void setPages(num pages) this.pages = pages return public void setPrice(num pr) price = pr return public string getTitle() return title public num getPages() return pages public num getPrice() return price endClass Find the Bugs Debug10-01 // The Date class contains a month, day, and year, // and methods to set and display the values. // The month cannot be set to less than 1 or more than 12, // and the day of the month cannot be set to less than 1 // or more than the number of days in that month. // The demonstration program instantiates four Date objects and // purposely assigns invalid values to some of the arguments; // the class methods will correct the invalid values. class Date Declarations private num month private num day private num year public void setDate(num mo, num da, num yr) num HIGH_MONTH = 12 num HIGHEST_DAYS[HIGH_MONTH] = 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 // value for December was missing if mo > HIGH_MONTH then month = HIGH_MONTH else if mo < 1 then month = 1 1. Your downloadable student files for Chapter 10 include DEBUG10-01.txt, DEBUG10-02.tx Answer :
else month = mo endif endif if da > HIGHEST_DAYS[month - 1] then day = HIGHEST_DAYS[month - 1] // must use month - 1 to access correct day else if da < 1 then day = 1 else day = da endif year = yr return public void showDate() output "Date: ", month, “/”, day, “/”, year return endClass start Declarations Date birthday, anniversary, graduation, party birthday.setDate(6, 24, 1982) // must use public setDate() method // cannot use private class members here anniversary.setDate(10, 15, 2009) graduation.setDate(14, 19, 2016) party.setDate(7, 35, 2015) output "Birthday " birthday.showDate() output "Anniversary " anniversary.showDate() output "Graduation " graduation.showDate() output "Party " party.showDate() stop Debug10-02 // The Invoice class contains invoice number, customer name, // balance due, and tax owed fields, // and methods to set and display the values.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture