King Fred of Id

The King of Id likes to think that he and his kingdom are most important. To that end he has decided that:

  1. All words should be uppercase.
  2. The only four letter word should be FRED , the king's name, note that it ends in "ed". This will also clean up the language of the people of Id. Example: SLED --> FRED
  3. All words that end in the letters "ed" should instead end in the letters "id"
    Example: BED --> BID
  4. All words that begin with "di" should have the first two letters reversed so that the word will be "id"
    Example: DIVER --> IDVER
  5. Rule #2 takes priority over Rules #3 and #4, that is, if you ever convert FRED to FRID you will likely be banished from the kingdom and never be able touch a computer again.

You have been hired by the King to write a program that will help the loyal subjects of Id translate any text to the new standard. (Use Scanner to get a word or sentence)

Sample Test Data

Word Translated Word
solved SOLVID
a A
very FRED
difficult IDFFICULT
math FRED
last FRED
night NIGHT

NOTE: the rules #3 and #4 ONLY apply to the first and last two letters. So the word "EDITED" should change to "EDITID", not "IDITID".
Similarly "DIZZZDIZZZDI" must end up as "IDZZZDIZZZDI"

Basic program: Write a program that will translate one word at a time
Advanced program: Change your program so that it will handle a whole sentence.