Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This exercise depends on these two classes: /JavaCS1/src/inheritanceI/Person.jav

ID: 3853740 • Letter: T

Question

This exercise depends on these two classes:

/JavaCS1/src/inheritanceI/Person.java
/JavaCS1/src/inheritanceI/Oldie.java

The Person class has a print method that writes a person's name and age to the console. Thus, if we create a Person object with these values:

Person p = new Person("Buster", 22);

then the call:

p.print();

will write the following output to the console:

In the same manner, we want to print information about objects in the subclass Oldie. Remember that Oldie objects contain the additional boolean datum perryComoFan. If we create an Oldie object with these values:

Oldie k = new Oldie("Cornelius", 93, true);

then the call: k.print(); should result in the following output to the console:

For this exercise, enter code in the box below that will allow the print method in the Oldie class to write the above specified output to the console. Note that your output must have the same format as that given in the example above.



/**
* This class contains data and methods pertaining
* to an oldie -- i.e. someone over the age of, oh say 30.
* The datum contained in this class is:
* whether or not this person is a Perry Como fan.
* This class derives from Person.
*/

public class Oldie extends Person
{
   private boolean perryComoFan;
    

   public boolean isPerryComoFan ()
   {
      return perryComoFan;
   }

   public void setPerryComoFan (boolean f)
   {
      perryComoFan = f;
   }

   public void print ()
   {

CODES LISTED BELOW

Explanation / Answer

MODEIFIED Oldie.java

package oldie.person;

/**

* This class contains data and methods pertaining

* to an oldie- i.e. someone over the age of, oh say 30.

* The datum contained in this class is:

* whether or not this person is a Perry Como fan.

* This class derives from Person.

*/

public class Oldie extends Person

{

private boolean perryComoFan;

  

public Oldie(String name, int age, boolean isFan)

{

super(name, age);

perryComoFan = isFan;

}

public boolean isPerryComoFan()

{

return perryComoFan;

}

public void setPerryComoFan(boolean f)

{

perryComoFan = f;

}

public void print( )

{

System.out.println("Name: " + getName());

System.out.println("Age: " + getAge());

System.out.println("Perry Fan: " + isPerryComoFan());

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote