Question
Exploring Inheritance Define a class named 'Document that includes a private data member of type String named 'text' that stores any textual contents for the
Exploring Inheritance Define a class named 'Document that includes a private data member of type String named 'text' that stores any textual contents for the document. Write two constructors, a no-argument (or default) constructor, and another with one argument of type String. The default constructor will initialize the member variable 'text' to an empty string, and the other constructor will initialize the member variable 'text' with the value of its argument. Create a method named toString that returns the text field
. (Don't add any getter or setter methods to this class.) Next, define a class named Email that is derived from Document and includes additional private member variables for the sender, recipient, and title of an email message. The body of the email message should be stored in the inherited member variable 'text'. Implement the following constructors and methods for this class, A no-argument constructor that initializes all four member variables with an empty string. A constructor with four arguments of type String that initializes every member variable with the value of the corresponding argument (text, sender, recipient, and title) Write getters and setters methods for member variables sender, recipient, and title.
Override the toString method to return a string representation of the email message (concatenate all the member variables each with its own appropriate label
). See sample output below. Similarly, define a class named 'File that is derived from Document, and includes a private member variable 'pathname' for the file's pathname. The file's content should be stored in the inherited member variable 'text'.
Write the following constructors and methods for this class, A no-argument constructor that initializes both member variables with an empty string. A constructor with two arguments of type String that initializes the inherited member variable 'text' with the value of the first argument, and \"pathname' with the value of the second argument. Write a getter method and a setter method for the member variable 'pathname'.
Override the toString method to return a string representation of the file (concatenate both member variables each with its own appropriate label). Finally, write a driver program (a main method) to test your classes. Create two objects of type Email, and two objects of type File in your main method (see sample output below). Print out the email objects first, and then the file objects. Next, use method contains' defined below to determine whether the word 'Java' appears in any of the email messages or file contents. If it does, output the name of those object(s). // Search the document for a target, return true if target is found. Otherwise, return false public static boolean contains (Document doc, String target) { If (doc.toString().indexOf(target, 0) >= 0) return true; return false; } Sample input/output: Programmer: Course: Lab: Due date: Name of the programmer (your name) COSC 211, W22 3 2-9-2022 Sender: Tom Recipient: Edward Title: super keyword message: The keyword super can be used in two ways in Java Sender: Speedy Recipient: Gonzales Title: races message: This message is about running marathons Pathname: input.txt File contents: Use Scanner to read from a Java text file Pathname: run.txt File contents: The name of participants in the last 10 marathon races Which object contains Java? Emaili Filel
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started