Bloomberg | Phone | Design a mailbox

Hi everyone,
I had this problem on my interview with Bloomberg.

Design a mailbox which should do the two functions:

  1. send a message.
  2. retrieve all messages of a user.

After I finished the requirements, he asked me to extend the code to provide these two functions:

  1. send an error message if a receiver doesn't exist.
  2. send one message to multiple users.

The problem was very straighforward and easy. I was able to communicate my thoughts and ideas with the interviewer. But after I finished the interview, and I felt that I will proceed to the next stage, I realized that my code could be better and improved. I guess the time constraint of the interview, and the overall stress were playing against me.
For example: (1) create a new class to save users, and make it a singelton class which has a set to store the users. (2) have a methods which validates if a user exists or not.

I will put my code here, and I am happy to receive your comments about it, and if you think I will pass it or not? Probably will get the feedback after the Christmas holidays. Merry Christmas everyone :)

import java.security.Timestamp;
import java.util.*;

public class MainClass {
	static Set<User> userDB;
	
	public static void main(String[] args) {
		userDB = new HashSet<User>();
		User user1 = new User();
		User user2 = new User();
		userDB.add(user1);
		userDB.add(user2);
		
		Message msg = new Message();
		msg.sender = user1;
		msg.receiever = user2;
		msg.body = "Hello";
		msg.timeSent = Timestamp.class.cast(" ");
		user1.mailBox.send(msg, user2);
	}
}

class Message{
	User sender;
	User receiever;
	String body;
	Timestamp timeSent;
}

class User{
	String name;
	String email;
	MailBox mailBox;
}

class MailBox{
	List<Message> inbox = new ArrayList<Message>();

	public void sendMultipleUsers(Message message, List<User> receiverList) {
		for(User receiver : receiverList) {
			send(message, receiver);
		}
	}
		
	public void send (Message message, User receiver) {
		if(MainClass.userDB.contains(receiver)) {
			receiver.mailBox.inbox.add(message);
		}
		else {
			Message msgError = new Message();
			msgError.sender.name = "Global System";
			msgError.receiever = null;
			msgError.body = "Error";
			msgError.timeSent = Timestamp.class.cast(" ");
			inbox.add(msgError);	
		}
	}
	
	public List<Message> retreiveAll(){
		return inbox;
	}
}
Comments (4)