A good answer might be:

Yes. All that Card asked for was:

public abstract void greeting();

Each sibling did that in its own way.


Complete Program

Here is a complete program with all three card classes and objects of each type. If you were deficient in greeting cards this year, you might wish to copy this to NotePad and run it a few times.

import java.io.*;

abstract class Card
{
  String recipient;
  public abstract void greeting();
}

class Holiday extends Card
{
  public Holiday( String r )
  {
    recipient = r;
  }

  public void greeting()
  {
    System.out.println("Dear " + recipient + ",\n");
    System.out.println("Season's Greetings!\n\n");
  }
}

class Birthday extends Card
{
  int age;

  public Birthday ( String r, int years )
  {
    recipient = r;
    age = years;
  }

  public void greeting()
  {
    System.out.println("Dear " + recipient + ",\n");
    System.out.println("Happy " + age + "th Birthday\n\n");
  }
}

class Valentine extends Card
{
  int kisses;

  public Valentine ( String r, int k )
  {
    recipient = r;
    kisses    = k;
  }

  public void greeting()
  {
    System.out.println("Dear " + recipient + ",\n");
    System.out.println("Love and Kisses,\n");
    for ( int j=0; j < kisses; j++ )
      System.out.print("X");
    System.out.println("\n\n");
  }
}

public class CardTester
{
  public static void main ( String[] args ) throws IOException
  {
    String me;
    BufferedReader input = new BufferedReader( new InputStreamReader(System.in) );
    System.out.println("Your name:");
    me = input.readLine();

    Holiday   hol = new Holiday( me );
    hol.greeting();

    Birthday  bd  = new Birthday( me, 21 );
    bd.greeting();

    Valentine val = new Valentine( me, 7 );
    val.greeting();

  }
}

QUESTION 9:

This is a fairly long program ― 80 lines! Do you think that you could design a few more card classes without any problems?