How would i Link up two walls to create a room?

I have been creating a system that would speed up the design a rooms and houses, however in the early stages I have already came to a blockade in the development. I want the user to be able to set the length of the X and Y walls to create the size of the room, however I want the system to automatically create the other walls to close off the space to create a room. I have already got the X and Y walls to be created, but I am having problems with the room creation part. Any help would be greatly appreciated.

You could try setting up snap or socket points for the walls on all for sides.