This is likely going to be a multi-step process but read through this post to get a better understanding of how line segments are joined.