Your downloadable student files for Chapter 10 include DEBUG10 01txt DEBUG10

Your downloadable student files for chapter 10

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, 8e Solutions 10-10 month = 1 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. // 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 Invoice Declarations private num invoiceNumber private string customer private num balanceDue
Programming Logic and Design, 8e Solutions 10-11 private num tax public void setInvoiceNumber(num number) // setInvoiceNumber() method should be public Declarations num LOW_NUM = 1000 num HIGH_NUM = 9999 if number > HIGH_NUM then invoiceNumber = 0 else if number < LOW_NUM then invoiceNumber = 0 else invoiceNumber = number endif endif return public void setCustomer(string cust) // setCustomer() should be public customer = cust return public void setBalanceDue(num balance) balanceDue = balance setTax() return private void setTax() // setTax() does not need any parameters Declarations num TAX_RATE = 0.07 tax = balanceDue * TAX_RATE return public void displayInvoice() output "Invoice #", invoiceNumber output "Customer: ", customer output "Due: ", balanceDue output "Tax: ", tax output "Total ", balance + tax return endClass start Declarations Invoice inv1 Invoice inv2 Invoice inv3 inv1.setInvoiceNumber(1244)

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture