How can I create beds programmatically?

Apart from having a bunch of methods whose functionality i can’t see, your biggest issue is that you need to place both parts of the bed down at the same time.

Basically, beds contain rotation data as well as data to tell it which end of the bed it is.

You need to create two blocks to place a proper bed, and be sure to assign the right data to the right blocks.

There’s not much I can do to help you other than that.