Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10 Object-Oriented Programming: Polymorphism.

Similar presentations


Presentation on theme: "Chapter 10 Object-Oriented Programming: Polymorphism."— Presentation transcript:

1 Chapter 10 Object-Oriented Programming: Polymorphism

2 Problem Description An employee is either a salaried employee or a hourly employee or a commission employee A base-salaried commission employee is a commission employee with a base salary Every employee has a first name, a last name, and a social security number In addition to the info above –The salaried employee has a weekly salary –The hourly employee has a wage per hour and number of hours worked –The commission employee has a commission rate and gross weekly sales –The base-salaried commission employee has a base salary, a commission rate, and gross weekly sales Develop a method to calculate the earnings for all kinds of employees

3

4

5

6

7 Example of a Salaried Employee First name: John Last name: Smith SSN: 111-11-1111 Weekly salary: 800 USD  Earnings = 800 USD

8

9

10 Example of a Hourly Employee First name: Karen Last name: Price SSN: 444-44-4444 Wage per hour: 16.75 USD If the number of hours worked is 40, the earnings will be 16.75  40 = 670 USD If the number of hours worked is 45, the earnings will be 16.75  40 + 16.75  (45 – 40)  1.5 = 670 + 125.625 = 795.625 USD

11

12

13 Example of a Commission Employee First name: Sue Last name: Jones SSN: 222-22-2222 Gross weekly sales: 10,000 USD Commission rate:.06  Earnings = 600 USD If the gross weekly sales is 500 USD and the commission rate is.1, the earnings will be 50 USD

14

15

16 Example of a Base Salaried Commission Employee First name: Bob Last name: Lewis SSN: 333-33-3333 Commission rate:.04 Base salary: 300 USD If the gross weekly sales is 5,000 USD, the earnings will be 500 USD

17

18

19 Case Study: Creating and Using Interfaces

20 Problem Description Develop a simple invoice that contains billing information for only one kind of part Billing information includes –The part number –The part description –The quantity –The price per item The invoice object should be able to calculate the amount of payment

21 Examples Example 1 –Part number: 01234 –Part description: Seat –Quantity: 2 –Price per item: 375.00  Payment amount = 750.00 Example 2 –Part number: 56789 –Part description: Tire –Quantity: 4 –Price per item: 79.95  Payment amount = 319.8

22

23

24

25

26 Question Q: What both classes Invoice and Employee have in common? A: Classes Invoice and Employee both represent things for which the company must be able to calculate a payment amount –But the way of calculation is different  We can use an interface called Payable to combine the two designs into one

27

28

29

30


Download ppt "Chapter 10 Object-Oriented Programming: Polymorphism."

Similar presentations


Ads by Google