Question

You are asked to finish the folloning programs. Duc on 07/05/18 (in classs). Considering a hierarchy of greeting cards. The parent class is Cards, and its children classes are Valentine, Holiday and Birthday, as shown below: In this exercise, Cards class is provided as below. As you can see, Cards class contains a recipients name in String type, and a method: greeting0. In this exercise, please implement the three Cards children classes: Valentine, Holiday, and Birthday, according to the following specifications: Valentine class contains its own data field: int kisses . Birthday class contains its own data field: int age. · Implement the constructor and greeting() method for each subclass. The constructor should initilize the subclasss data field as well as its parents data field. The greetingo method outputs the message related to its own subclass and should contain the information of its atributes. The example greeting messa e example greeting messages are followings: reespiest public cards) his(Jahn Smith ): public CardscSering recipient this recipient recipient; public veid greeting Systen out.printin wish you a wonder ful sumer Your three subclasses should work with the following driver program CardTest.java publ.ic ctass CardTest polic static vold Bain(String[] args) Card card - new Holidayl Alsce) card. greeting card sew Val ent inel Bob. 12) card greeting card sew Birthdayl Charlie. 4) card greeting Submission: print out four files: Valentine.java, Holiday java, Birthday.java, and CardTest.java, and append your result at the end.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi please find the answer

If you have any query please let me know first by comment i will give soultions

Create a package and then create all java classes with same name as give below then copy and paste code given below on respective file

===============================================================================

Cards.java

public class Cards {

//variable

String recipient;

//constructor

public Cards()

{

this("John Smith");

}

//constructor with one parameter

public Cards(String recipient)

{

this.recipient=recipient;

}

// greeting method

public void greeting()

{

System.out.println("Dear " + recipient+ ":\n");

System.out.println("Wish you a wonderful summer");

}

}

=====================================================================

Holiday.java

// this class inherit or extends the parent class Cards

public class Holiday extends Cards {

//constructor

public Holiday(String recipient)

{

/// call Parent class constructor variable

super.recipient =recipient;

}

// override the super class greeting method

public void greeting()

{

System.out.print("Holiday : ");

System.out.println("Dear " + recipient);

System.out.print("Season's Greetings! \n");

}

}

=============================================================

Valentine.java

//this class inherit or extends the parent class Cards

public class Valentine extends Cards {

//variable declaration

int kisses;

//getter

public int getKisses() {

return kisses;

}

//setter

public void setKisses(int kisses) {

this.kisses = kisses;

}

//constructor

public Valentine(String recipient,int kisses)

{

this.kisses=kisses;

// call Parent class constructor variable

super.recipient=recipient;

}

// override the super class greeting method

public void greeting()

{

System.out.print("\nValentine : ");

System.out.println("Dear " + recipient+ ",");

System.out.println("Love and Kisse,");

System.out.print("XXXXX... ( " + getKisses() + " Number of 'X' )\n");

}

}

===================================================================

Birthday.java

//this class inherit or extends the parent class Cards

public class Birthday extends Cards {

// variable

int age;

//getter

public int getAge() {

return age;

}

//setter

public void setAge(int age) {

this.age = age;

}

// constructor

public Birthday( String recipient,int age)

{

this.age=age;

// call Parent class constructor variable

super.recipient=recipient;

}

// override the super class greeting method

public void greeting()

{

System.out.print("\nBirthday : ");

System.out.println("Dear " + recipient);

System.out.print("Happy " + age +"th Birthday!");

}

}

==================================================================

CardTest.java

// main driver Class

public class CardTest {

// main method

public static void main(String[] args) {

// create the object of Holiday with referencing of Parent Cards class

// and initialize a value to variable by constructor

Cards card = new Holiday("Alice");

// call the greeting method

card.greeting();

// create the object of Valentine with referencing of Parent Cards class

// and initialize a value to variable by constructor

card = new Valentine("Bob", 12);

// call the greeting method

card.greeting();

// create the object of Birthday with referencing of Parent Cards class

// and initialize a value to variable by constructor

card = new Birthday("Charlie", 4);

// call the greeting method

card.greeting();

}

}

======================================================================

Output

==========================================================

If you have any query please let me know first by comment i will give soultions

Add a comment
Know the answer?
Add Answer to:
You are asked to finish the folloning programs. Duc on 07/05/18 (in classs). Considering a hierarchy...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Y. Daniel Liang’s 8 Class Design Guidelines were posted on the File Manager and handed out...

    Y. Daniel Liang’s 8 Class Design Guidelines were posted on the File Manager and handed out in class. Please choose 5 guidelines and discuss them in depth. For each guideline, use 1 page or more for your discussion. You can use the code provided in class to demonstrate your points. The code should not be more than one-third of your writing. 1. Cohesion • [✓] A class should describe a single entity, and all the class operations should logically fit...

  • (1)     ____ is the principle that allows you to apply your knowledge of a general category...

    (1)     ____ is the principle that allows you to apply your knowledge of a general category to more specific objects.           a.       Inheritance              c.       Encapsulation           b.       Polymorphism                    d.       Override (2)     When you create a class by making it inherit from another class, you are provided with data fields and ____ automatically.           a.       fonts                      c.       class names           b.       methods                  d.       arrays (3)     By convention, a class diagram contains the ____ following each attribute or...

  • C++ help This assignment gives you practice with inheritance and pure virtual functions. You will implement...

    C++ help This assignment gives you practice with inheritance and pure virtual functions. You will implement some code that could be part of a program to play a popular card game called “Crazy 8’s”, which is the basis for the game “Uno”. You will start to implement the rules, as described at: https://www.pagat.com/eights/crazy8s.html . Note that the inheritance relationship below is also based on the organization of card games described on that website. Requirements: your work will be split into...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by...

    Java: student directory GUI You need to implement three classes: Person Student StudentDirectory StudentMain Start by implementing Person and Student classes. Once you are sure you can serialize and deserialize and ArrayList of Students to and from a file, move on to building the GUI application. Person: The Person class should implement serializable interface. It contains the following: Person's first name (String) Person's last name (String) Person's id number Person's date of birth (Date) public String toString(): This method method...

  • Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal...

    Hello, In need of help with this Java pa homework. Thank you! 2. Create a normal (POJo, JavaBean) class to represent, i. e. model, varieties of green beans (also known as string beans or snap beans). Following the steps shown in "Assignment: Tutorial on Creating Classes in IntelliJ", create the class in a file of its own in the same package as class Main. Name the class an appropriate name. The class must have (a) private field variables of appropriate...

  • Hi i will give you a thumbs up if you do this problem correctly. Sorting Analysis Code and Essay ...

    Hi i will give you a thumbs up if you do this problem correctly. Sorting Analysis Code and Essay Due: 4/22/2019(Monday) Introduction And now for something completely different.   Different sorting algorithms are better for different size data sets.   Other sorting algorithms are better for data sets of a specific type – for instance, data that is already ordered. In this assignment you will implement four different sorting algorithms and collect statistics for each of those algorithms while sorting multiple different...

  • ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag...

    ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and...

    The purpose of this is to use inheritance, polymorphism, object comparison, sorting, reading binary files, and writing binary files. In this application you will modify a previous project. The previous project created a hierarchy of classes modeling a company that produces and sells parts. Some of the parts were purchased and resold. These were modeled by the PurchasedPart class. Some of the parts were manufactured and sold. These were modeled by the ManufacturedPart class. In this you will add a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT