MP07

More Inheritance*


Introdution

This assignment is designed to familiarize you with the mechanics of inheritance.

Part 1

Define a class named Payment that contains a member variable of type double that stores the amount of the payment and appropriate accessor and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment.

Next, define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails method to indicate that the payment is in cash. Include appropriate constructor(s).

Define a class named CreditCardPayment that is derived from Payment. This class should contain member variables for the name on the card, expiration date, and credit card number. Include appropriate constructor(s). Finally, redefine the paymentDetails method to include all credit card information in the printout.

Create a main (mp07a) method that creates at least two CashPayment and two CreditCardPayment objects with different values and calls paymentDetails for each.

Using a compression program, zip up all the project files into a file called mp07a.zip.

Part 2

Define a class named Document that contains a member variable of type String named text that stores any textual content for the document. Create a method named tostring that returns the text field and also include a method to set this value.

Next, define a class for Email that is derived from Document and includes member variables for the sender, recipient, and title of an email message. Implement appropriate accessor and mutator methods. The body of the email message should be stored in the inherited variable text. Redefine the tostring method to concatenate all text fields.

Similarly, define a class for File that is derived from Document and includes a member variable for the pathname. The textual contents of the file should be stored in the inherited variable text. Redefine the tostring method to concatenate all text fields.

Finally, create several sample objects of type Email and File in your main (mp07b) method. Test your objects by passing them to the following method that returns true if the object contains the specified keyword in the text property.

public static boolean ContainsKeyword(Document docObject, String keyword) { 
	if (docObject.tostring()indexOf(keyword,0) >= 0) return true; 
	return false; 
} 

Using a compression program, zip up all the project files into a file called mp07b.zip.

What to Turn In

Using your compression utility, zip up mp07a.zip and mp07b.zip into a file called mp07.zip. Submit this file to the homework submission system.


* based on assignments from here.