In: Computer Science
// Programmer:
// Date:
// The Saurian class has the ability to translate English to
Saurian
// and Saurian to English
public class Saurian
{
// data
// constants used for translating
// note M = M and m = m so M and m are not
needed
public static final char[] ENGLISHARR =
{'A','B','C','D','E','F','G','H','I','J','K','L','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','n','o','p','q','r','s','t','u','v','w','x','y','z'};
public static final char[] SAURIANARR =
{'U','R','S','T','O','V','W','X','A','Z','B','C','D','E','F','G','H','J','K','I','L','N','P','O','Q','u','r','s','t','o','v','w','x','a','z','b','c','d','e','f','g','h','j','k','i','l','n','p','o','q'};
public static final int ARRLENGTH =
ENGLISHARR.length; // should be the same length for
ENGLISHARR and SAURIANARR
}
// Programmer: // Date: // The Saurian class has the ability to translate English to Saurian // and Saurian to English import java.util.Scanner; public class Saurian { // data // constants used for translating // note M = M and m = m so M and m are not needed public static final char[] ENGLISHARR = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; public static final char[] SAURIANARR = {'U', 'R', 'S', 'T', 'O', 'V', 'W', 'X', 'A', 'Z', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'I', 'L', 'N', 'P', 'O', 'Q', 'u', 'r', 's', 't', 'o', 'v', 'w', 'x', 'a', 'z', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'i', 'l', 'n', 'p', 'o', 'q'}; public static final int ARRLENGTH = ENGLISHARR.length; // should be the same length for ENGLISHARR and SAURIANARR public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter sentence in english: "); String line = in.nextLine(); String result = ""; for (int i = 0; i < line.length(); i++) { int index = -1; for (int j = 0; j < ARRLENGTH; j++) { if (line.charAt(i) == ENGLISHARR[j]) { index = i; break; } } if (index == -1) result += line.charAt(i); else result += SAURIANARR[index]; } System.out.println(result); } }