Question: Function overloading or method overloading allows oneto create multiple functions of the same name with different implementations. make a class named Chat . Add

Function overloading or method overloading allows one to create multiple functions of the same name with different implementations.

 

make a class named Chat.

Add the following variables:

1. List members - A list of all members in the chat.

2. List files - A list of all files in the chat.

3. HashMap message - A list of all messages in the chat.

 

Add the following methods:

1. void Chat() - Initializes members , files, message.

2. Method add which has 3 variations, each with a return type void:. 

  • Variation 1 has a parameter String[] names . This copies the values from names to the list members.
  • Variation 2 has a parameter int[] ids . This copies the values from ids to the list files.
  • Variation 3 has 2 parameters:  int id and String newMessage. This adds the key value pair <id, newMessage> to the map message.

3. Method remove which has 3 variations, each with a return type void:.

  • Variation 1 has a parameter String[] names. This removes all the values in names from the list members. If some name does not exist, print "Member with name {name} does not exist".
  • Variation 2 has a parameter int[] ids. This removes all the values in ids from the list files. If some id does not exist, print "File with id {id} does not exist".
  • Variation 3 has a parameter int id. This removes the message with the key id from the map message. If some id does not exist, print "Message with id {id} does not exist".

4. void printConversation() - Prints the following -

"Total number of members in the conversation are {totalMembers}"

"The names of these members are {all the names}" where the names are separated by a single space.

"Total number of files in the conversation are {totalFiles}"

"The messages in the conversation are {all the messages}"  where each message is surrounded by single quotes and messages are separated by a single space.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Heres the implementation of the Chat class with the requested variables and methods import javautil public class Chat private List String members priv... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!