Question: This exercise depends on these two classes: /** * This class contains data and methods pertaining * to a person. The data contained in this
This exercise depends on these two classes:
/** * This class contains data and methods pertaining * to a person. The data contained in this class are: * name and age. */ public class Person { private String name; private int age; public Person(String n, int a) { this.name = n; this.age = a; } public String getName() { return name; } public int getAge() { return age; } public void setName(String n) { name = n; } public void setAge(int a) { age = a; } public void print( ) { System.out.println("Name: " + name); System.out.println("Age: " + age); } } /** * 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( ) { /* your code here */ } } 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:
Name: Buster Age: 22
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:
Name: Cornelius Age: 93 Perry Fan: true
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 () {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
