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: Help with method plz..

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    11
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help with method plz..

    Help with this code please.. im not sure how to go about this.

    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:

    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.

    public class Oldie extends Person
    {
       private boolean perryComoFan;
     
     
       public boolean isPerryComoFan ()
       {
          return perryComoFan;
       }
     
       public void setPerryComoFan (boolean f)
       {
          perryComoFan = f;
       }
     
       public void print ()
       {


  2. #2
    Member vanDarg's Avatar
    Join Date
    Jan 2011
    Location
    Chicago
    Posts
    65
    My Mood
    Mellow
    Thanks
    1
    Thanked 7 Times in 7 Posts

    Default Re: Help with method plz..

    You have to write a constructor here, which takes 3 parameters. A string for name, an integer for age, and a boolean value for a Perry fan.

    This constructor should also call a constructor for a Person.
    Last edited by vanDarg; April 1st, 2011 at 01:51 PM.
    "Everything should be made as simple as possible, but not simpler."
    Asking Questions for Dummies | The Java Tutorials | Java Coding Styling Guide

  3. #3
    Member
    Join Date
    Feb 2011
    Posts
    55
    My Mood
    Tolerant
    Thanks
    1
    Thanked 16 Times in 15 Posts

    Default Re: Help with method plz..

    Also, instead of rewriting the print from scratch and introducing code duplication, call the print from the parent first, then add the perryComoFan println.

Similar Threads

  1. Help with toString method and an addObject method?
    By Camisado in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 12th, 2011, 07:00 AM
  2. Can i call init() method in destroy method.?
    By muralidhar in forum Java Servlet
    Replies: 1
    Last Post: October 22nd, 2010, 11:18 AM