100%(8)8 out of 8 people found this document helpful
This preview shows page 9 - 12 out of 17 pages.
1.Your downloadable student files for Chapter 10 include DEBUG10-01.txt, DEBUG10-02.txt, and DEBUG10-03.txt. Each file starts with some comments that describe the problem. Comments are lines that begin with two slashes (//). Following the comments, each file contains pseudocode that has one or more bugs you must findand correct.
Programming Logic and Design, 8eSolutions 10-10month = 1elsemonth = moendifendifif da > HIGHEST_DAYS[month - 1] thenday = HIGHEST_DAYS[month - 1]// must use month - 1 to access correct dayelseif da < 1 thenday = 1elseday = daendifyear = yrreturnpublic void showDate()output "Date: ", month, “/”, day, “/”, yearreturnendClassstartDeclarationsDate birthday, anniversary, graduation, partybirthday.setDate(6, 24, 1982)// must use public setDate() method// cannot use private class members hereanniversary.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()stopDebug10-02// The Invoice class contains invoice number, customer name,// balance due, and tax owed fields,// and methods to set and display the values.// The invoice number must be between 1000 and 9999 inclusive// or else it is set to 0// Tax is 7 % of the balance due// The demonstration program instantiates three Invoices and// purposely assigns invalid values to some of the arguments;// the class methods will correct the invalid values.class InvoiceDeclarationsprivate num invoiceNumberprivate string customerprivate num balanceDue
Programming Logic and Design, 8eSolutions 10-11private num taxpublic void setInvoiceNumber(num number)// setInvoiceNumber() method should be publicDeclarationsnum LOW_NUM = 1000num HIGH_NUM = 9999if number > HIGH_NUM theninvoiceNumber = 0elseif number < LOW_NUM theninvoiceNumber = 0elseinvoiceNumber = numberendifendifreturnpublic void setCustomer(string cust)// setCustomer() should be publiccustomer = custreturnpublic void setBalanceDue(num balance)balanceDue = balancesetTax()returnprivate void setTax()// setTax() does not need any parametersDeclarationsnum TAX_RATE = 0.07tax = balanceDue * TAX_RATEreturn public void displayInvoice()output "Invoice #", invoiceNumberoutput "Customer: ", customeroutput "Due: ", balanceDueoutput "Tax: ", taxoutput "Total ", balance + taxreturnendClassstartDeclarationsInvoice inv1Invoice inv2Invoice inv3inv1.setInvoiceNumber(1244)