Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: I dont know how to complete this code?

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I dont know how to complete this code?

    OK below is the prompt I got for this homework assignment. I have been able to write almost all of it but I cant figure out the last bit.
    Prompt-
    "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:
    Name: Buster
    Age: 22
    We want to provide similar printed information information for objects in the subclass CollegeKid. Remember that CollegeKid objects 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:
    Name: Zoe
    Age: 23
    GPA: 3.75
    For this exercise, enter code in the box below that will allow the print method in the CollegeKid class to override print in the Person 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."

    public class CollegeKid extends Person
    {
       private double gpa;
     
     
       public double getGPA ()
       {
          return gpa;
       }
     
       public void setGPA (double g)
       {
          gpa = g;
       }
     
       public void print ( )
       {
     
     This is what im missing
     
     
       } 
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I dont know how to complete this code?

    How did you code the print() method in the Person class?
    What needs to be added to the ouput for the CollegeKid class?

    Start by copying the code from the Person class then modify it for the new requirements.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I dont know how to complete this code?

    super.print();
    System.out.println("GPA: " + gpa);

Similar Threads

  1. I dont get it....please help
    By DestinyChick1225 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: June 30th, 2010, 03:16 AM
  2. Unable to render printing the complete JPanel
    By Stephen Douglas in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 13th, 2010, 11:48 AM
  3. Dont laugh at me
    By Neblin in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 3rd, 2009, 08:18 AM
  4. How to delete and add elements to an array dynamically?
    By k_w_r2007 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 21st, 2009, 11:31 AM