Question

In: Computer Science

// Programmer: // Date: // The Saurian class has the ability to translate English to Saurian...

// 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

}

Solutions

Expert Solution

// 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);
    }
}


Related Solutions

A researcher has studied subjects’ ability to learn to translate words into Morse code. He has...
A researcher has studied subjects’ ability to learn to translate words into Morse code. He has experimented with two treatment conditions: in one condition, the subjects are given massed practice; they spend 6 full hours on the task. In the other condition, subjects are given distributed practice; they also spend 6 hours, but their practice is spread over four days, practicing 2 hours at a time. After the practice, all subjects are given a test message to encode; the dependent...
The Date Class This class will function similarly in spirit to the Date class in the...
The Date Class This class will function similarly in spirit to the Date class in the text, and behaves very much like a “standard” class should. It should store a month, day, and year, in addition to providing useful functions like date reporting (toString()), date setting (constructors and getters/setters), as well as some basic error detection (for example, all month values should be between 1-12, if represented as an integer). Start this by defining a new class called “Date” or...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
Arrays provide the programmer the ability to store a group of related variables in a list...
Arrays provide the programmer the ability to store a group of related variables in a list that can be accessed via an index. This is often very useful as most programs perform the same series of calculations on every element in the array. To create an array of 10 integers (with predefined values) the following code segment can be utilised: int valueList[10] = {4,7,1,36,23,67,61,887,12,53}; To step through the array the index '[n]' need to be updated. One method of stepping...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
The uncertainty associated with a firms ability to translate EBIT into earnings per share is A....
The uncertainty associated with a firms ability to translate EBIT into earnings per share is A. Operational risk B. Financial risk C. Risk of illiquidity D. None of the above.
this is Discrete mathematics problem. Translate the following English sentences into propositional formulas. Remember to def...
this is Discrete mathematics problem. Translate the following English sentences into propositional formulas. Remember to def ne your atomic propositions! (a) Either the suspect wore gloves, or he didn't touch the doorknob. (b) I will eat my tie if the Cubs win the World Series. (c) It smelled funny, but he ate it anyway. (d) The people will give up their arms only when the tyrant resigns and we get our money back. (e) All prizes will be awarded provided...
Part 1: Below are basic arguments in English. Choose one argument and translate the argument into...
Part 1: Below are basic arguments in English. Choose one argument and translate the argument into the symbolism of predicate logic. Use one of the proof techniques from Chapter 8 to demonstrate the validity of the argument. 1. Every fetus has an immortal soul. A thing has an immortal soul only if it has a right to life. Hence, every fetus has a right to life. (Fx = x is a fetus, Sx = x has an immortal soul, Rx...
Each entry-level software programmer in Palo Alto, California, has either high or low ability. All potential...
Each entry-level software programmer in Palo Alto, California, has either high or low ability. All potential employers value a high-ability worker at $12,000 per month and a low-ability worker at $6,000. The supply of high ability workers is Qh = 0.1(W - 7,000) and the supply of low-ability workers is Ql= 0.1(W - 2,000), where W is the monthly wage. a) If workers’ abilities are observable to employers, how many workers of each type will employers hire? b) If workers’...
Python: What are the defintions of the three method below for a class Date? class Date(object):...
Python: What are the defintions of the three method below for a class Date? class Date(object): "Represents a Calendar date"    def __init__(self, day=0, month=0, year=0): "Initialize" pass def __str__(self): "Return a printable string representing the date: m/d/y" pass    def before(self, other): "Is this date before that?"
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT