must use month 1 to access correct day else if da 1 then day 1 else day da

Must use month 1 to access correct day else if da 1

This preview shows page 24 - 27 out of 31 pages.

// 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;
Programming Logic and Design, 8e Solutions 10-25 // the class methods will correct the invalid values. class Invoice Declarations private num invoiceNumber private string customer private num balanceDue 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) // setInvoiceNUmber() was spelled incorrectly inv1.setCustomer("Brown") inv1.setBalanceDue(1000.00) inv1.displayInvoice() inv2.setInvoiceNumber(77777) inv2.setCustomer("Jenkins")
Programming Logic and Design, 8e Solutions 10-26 inv2.setBalanceDue(2000.00) inv2.displayInvoice() inv3.setInvoiceNumber(888) inv3.setCustomer("Russell") inv3.setBalanceDue(3000.00) inv3.displayInvoice() stop Debug10-03 // The Mortgage class contains fields for mortgage // number, customer name, price of house, down // payment, mortgage amount, and mortgage rate, // and methods to set and get the values. // The mortgage number must be betwen 10000 and 59999 inclusive // or else it is set to 0 // The down payemnt cannot be more than the price of the house // If it is, an error message is displayed // and the down payment is reduced // The mortage amount is the difference between the house price // and the down payment // The mortgage rate differs for loans of different sizes // Loans over $200,000 get a preferred rate // The demonstration program instantiates three Mortgages and // purposely assigns invalid values to some of the arguments; // the class methods will correct the invalid values.

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture