I don't fully understand why an A sharp is not a B flat, or F flat is not an E. They sound the same so why are they different?

Please note this is an example topic. You can still reply if you like.