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

This exercise depends on the following two classes: /JavaCS1/src/inheritanceI/Pe

ID: 3687066 • Letter: T

Question

This exercise depends on the following two classes:

/JavaCS1/src/inheritanceI/Person.java
/JavaCS1/src/inheritanceI/CollegeKid.java

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

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

the call:


p.print();


would result in the following output to the console:

We want to provide similar printed information information for objects in the subclass CollegeKid. Remember that CollegeKidobjects contain the additional datum gpa. If we created a CollegeKid object with these values:

CollegeKid k = new CollegeKid("Zoe", 23, 3.75);

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 CollegeKid class to override print in thePerson class, and thus write the above specified output to the console. Note that your output must have the same format as in the example above.


/**
* This class contains data and methods pertaining
* to a college kid. The datum contained in this class is:
* grade point average -- gpa. This class derives from Person.
*/

public class CollegeKid extends Person
{
   private double gpa;


   public double getGPA ()
   {
      return gpa;
   }

   public void setGPA (double g)
   {
      gpa = g;
   }

   public void print ( )
   {

CODE GOES HERE

Here are the provided classes:

AND

  

Explanation / Answer

Hello there ,

Kindly find below code for CollegeKid.java class

/**
* This class contains data and methods pertaining
* to a college kid. The datum contained in this class is:
* grade point average- gpa. This class derives from Person.
*/

public class CollegeKid extends Person
{
   private double gpa;

public CollegeKid(String n, int a,double gpa) {
       super(n, a);
       this.gpa=gpa;
   }

public double getGPA()
{
return gpa;
}

public void setGPA(double g)
{
gpa = g;
}

@Override
public void print( )
{
super.print();
System.out.println("GPA: " + gpa);
}
  
}

=====


public class PrintApp {
   public static void main(String[] args){
       Person p = new Person("Buster", 22);
       p.print();
       System.out.println(" ");
       CollegeKid k = new CollegeKid("Zoe", 23, 3.75);
       k.print();
   }
}

===O/P===

Name: Buster
Age: 22


Name: Zoe
Age: 23
GPA: 3.75

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