Question: Add a new method called print() The print() method is similar to the display method, but it will print the data to a file called

Add a new method called print()

The print() method is similar to the display method, but it will print the data to a file called "mydata.txt" rather then to the screen

The file should append new data every time the print() method is called, and not replace it

2. Create a subclass

Create a sub class that inherits everything from your base class. (For example, if cell phone is the base class then smart phone could be your sub class)

Provide at least one additional attribute to your subclass

Create gettter/setter methods for it.

Create a default constructor for the subclass, that uses super to call the base class default constructor.

It should set all attributes in the subclass as well as the super class to default values

Create a parameterized constructor for the subclass, that uses keyword super to pass the inherited parameters to the base class.

It should set all attributes in the subclass as well as the super class to the values that are passed in to the constructor.

Override the print() method to print out (to the file "mydata.txt") all the instance variable values from the base class, and also from the sub class.

3. Update main method

In your main method, create 2 new object using your subclass

Create one object using the no-arg (default) constructor of your sub-class.

Call the set methods to set all attribute data associated to that object.

Create one object using the parameterized constructor of your sub-class.

Create an ArrayList containing these 2 objects, and also the 2 objects from your BA5 assignment to have at least 4 total objects inside it.

Loop through the ArrayList using a for loop and call the print() method for each object.

Create a Java Interface called Displayable that declares the display() and print() methods. Both your class and subclass should implement the interface.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!