Tham khảo sách 'java™ how to program ( deitel - deitel) - phần 18', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Salaried Employee . Declaring Interface Payable The declaration of interface Payable begins in Fig. at line 4. Interface Payable contains public abstract method getPaymentAmount line 6 . Note that the method is not explicitly declared public or abstract. Interface methods must be public and abstract so they do not need to be declared as such. Interface Payable has only one methodinterfaces can have any number of methods. We will see later in the book the notion of tagging interfaces these actually have no methods. In fact a tagging interface contains no constant values eitherit simply contains an empty interface declaration. In addition method getPaymentAmount has no parameters but interface methods can have parameters. Page 487 Figure . Payable interface declaration. 1 Fig. 2 Payable interface declaration. 3 4 public interface Payable 5 6 double getPaymentAmount calculate payment no implementation 7 end interface Payable . Creating Class Invoice We now create class Invoice Fig. to represent a simple invoice that contains billing information for only one kind of part. The class declares private instance variables partNumber partDescription quantity and pricePerltem in lines 69 that indicate the part number a description of the part the quantity of the part ordered and the price per item. Class invoice also contains a constructor lines 1219 get and set methods lines 2267 that manipulate the class s instance variables and a tostring method lines 7075 that returns a string representation of an Invoice object. Note that methods setQuantity lines 4649 and setPricePerltem lines 5861 ensure that quantity and pricePeritem obtain only non-negative values. Page 489 Figure . Invoice class that implements Payable. This item is displayed on pages 487 - 488 in the print version 1 Fig. 2 Invoice class implements Payable. 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34