Description
ASSIGNMENT 9: Inheritance
Total Points:100
1. Write a program to show single inheritance [CO2: BL:3] points: 25
Class LivingBeing
Methods: Breath() and Response()
Class Animal
Methods: Walk() and NoOfLegs()
2. Write a program to show Multilevel inheritance[CO2: BL:3]points:25
Class LivingBeing
Methods: Breath() and Response()
Class Animal
Methods: Walk() and NoOfLegs()
Class Cat
Methods: Meow()
Class Dog
Methods: Bark()
3. Write a program in Java to create messaging service like WhatsApp that uses single inheritance, multilevel inheritance, and hierarchical inheritance [CO:2, BL:6] points:50 class User:
Attributes
name phoneNumber
status subclass Contact: Stores contacts
Attributes
contactList code snippet :
class Contact extends User { protected User[] contacts; protected int contactCount;
… public void addContact(User user) {
…
}
}
class Message: Contains information about message
Attributes
sender receiver messageContent subclass Chat: represent chat between two users.:
Attributes
Users (an array of User objects) messages (an array of Message objects) Methods addMessages: add message to the chat displayChatHistory : display the chat history code snippet: class Chat { private User[] participants; private Message[] messages;
}
Create a main class WhatsApp to test the concepts public class WhatsApp {
public static void main(String[] args) {
User alice = new User(“Alice”, “+1234567890”, “Available”);
User bob = new User(“Bob”, “+9876543210”, “Away”);
Contact aliceContacts = new Contact(“Alice”, “+1234567890”,
“Available”, 10);
aliceContacts.addContact(bob);
Message message1 = new Message(alice, bob, “Hi, Bob!”);
Message message2 = new Message(bob, alice, “Hello, Alice!”);
Chat chat = new Chat(alice, bob, 100); chat.addMessage(message1); chat.addMessage(message2); chat.displayChatHistory();
}
}
CO2: To familiarize the student with Object Oriented Programming in Java
BL6: Create BL3: Apply




Reviews
There are no reviews yet.