There are a few ways I go about writing melodies (but not limited to):
1) Write out a chord progression; improvise something with lyrics already written
2) Write out a chord progression; improvise something without lyrics already written
3) Write out a chord progression; write out the melody based on the chord progression
4) Write a melody first keeping in mind the form of the song. Sometimes chorus first, sometimes verse first. (sometimes I keep in mind some similar motivic ideas or sometimes I'll use a lot of leaps or just stepwise things, etc.)
5) Write a melody based on the feel and direction of the lyrics, then write chords to the melody.
6) Improvise a melody over another song's chord progression and reharmonize it!
-Norman