Use the program shown in Table 1, then change the interface Payable to an Abstra
ID: 3648275 • Letter: U
Question
Use the program shown in Table 1, then change the interface Payable to an Abstract class. Payable interface declaration 1 // Payable.java 2 // Payable interface declaration. 3 4 public interface Payable 5 { 6 double getPaymentAmount(); // calculate payment; no implementation 7 } // end interface Payable Invoice class that implements Payable 1 // Invoice.java 2 // Invoice class implements Payable. 3 4 public class Invoice implements Payable 5 { 6 private String partNumber; 7 private String partDescription; 8 private int quantity; 9 private double pricePerItem; 10 11 // four-argument constructor 12 public Invoice( String part, String description, int count, 13 double price ) 14 { 15 partNumber = part; 16 partDescription = description; 17 setQuantity( count ); // validate and store quantity 18 setPricePerItem( price ); // validate and store price per item 19 } // end four-argument Invoice constructor 20 21 // set part number 22 public void setPartNumber( String part ) 23 { 24 partNumber = part; 25 } // end method setPartNumber 26 27 // get part number 28 public String getPartNumber() 29 { 30 return partNumber; 31 } // end method getPartNumber 32 33 // set description 34 public void setPartDescription( String description ) 35 { 36 partDescription = description; 37 } // end method setPartDescription 38 39 // get description 40 public String getPartDescription() 41 { 42 return partDescription; 43 } // end method getPartDescription 44 45 // set quantity 46 public void setQuantity( int count ) 47 { 48 quantity = ( count < 0 ) ? 0 : count; // quantity cannot be negative 49 } // end method setQuantity 50 51 // get quantity 52 public int getQuantity() 53 { 54 return quantity; 55 } // end method getQuantity 56 57 // set price per item 58 public void setPricePerItem( double price ) 59 { 60 pricePerItem = ( price < 0.0 ) ? 0.0 : price; // validate price 61 } // end method setPricePerItem 62 63 // get price per item 64 public double getPricePerItem() 65 { 66 return pricePerItem; 67 } // end method getPricePerItem 68 69 // return String representation of Invoice object 70 public String toString() 71 { 72 return String.format( "%s: %s: %s (%s) %s: %d %s: $%,.2f", 73 "invoice", "part number", getPartNumber(), getPartDescription(), 74 "quantity", getQuantity(), "price per item", getPricePerItem() ); 75 } // end method toString 76 77 // method required to carry out contract with interface Payable 78 public double getPaymentAmount() 79 { 80 return getQuantity() * getPricePerItem(); // calculate total cost 81 } // end method getPaymentAmount 82 } // end class Invoice Payable interface test program processing Invoices and Employees polymorphically. 1 // PayableInterfaceTest.java 2 // Tests interface Payable. 3 4 public class PayableInterfaceTest 5 { 6 public static void main( String args[] ) 7 { 8 // create four-element Payable array 9 Payable payableObjects[] = new Payable[ 4 ]; 10 11 // populate array with objects that implement Payable 12 payableObjects[ 0 ] = new Invoice( "01234", "seat", 2, 375.00 ); 13 payableObjects[ 1 ] = new Invoice( "56789", "tire", 4, 79.95 ); 14 payableObjects[ 2 ] = 15 new SalariedEmployee( "John", "Smith", "111-11-1111", 800.00 ); 16 payableObjects[ 3 ] = 17 new SalariedEmployee( "Lisa", "Barnes", "888-88-8888", 1200.00 ); 18 19 System.out.println( 20 "Invoices and Employees processed polymorphically: " ); 21 22 // generically process each element in array payableObjects 23 for ( Payable currentPayable : payableObjects ) 24 { 25 // output currentPayable and its appropriate payment amount 26 System.out.printf( "%s %s: $%,.2f ", 27 currentPayable.toString(), 28 "payment due", currentPayable.getPaymentAmount() ); 29 } // end for 30 } // end main 31 } // end class PayableInterfaceTestExplanation / Answer
NOT IN ORDER . NOT CLEAR , ITS SCAM , RE POST
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.