Question

Spell it out! Use the following Java concepts to compile the program below:   String myName =...

Spell it out! Use the following Java concepts to compile the program below:

  String myName = "Chuck";

    int length = myName.length();

    char firstChar = myName.charAt(0);

    char secondChar = myName.charAt(1);

    if (myName.equals("Tom")) {

      System.out.println ("Sorry, Tom!");

  }

Write a program that uses a METHOD to translate these individual characters:

  input output input output input output input output input output

a

4

g

9

m

/\\/\\

s

$

y

‘/

b

B

h

|-|

n

|\\|

t

7

z

Z

c

(

i

1

o

0

u

U

d

D

j

j

p

P

v

\\/

e

3

k

|<

q

Q

w

\\/\\/

f

Ph

l

L

r

R

x

><

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class Test {
        
        public static String translateString(String s) {
                String convertedChars[] = {"4" ,"B" ,"(" ,"D" ,"3" ,"Ph" ,"9" ,"|-|" 
                                ,"1" ,"j" ,"|<" ,"L" ,"/\\/\\" ,"|\\|"
                                ,"0" ,"P" ,"Q" ,"R" ,"$" ,"7" ,"U" ,"\\/" ,"\\/\\/"
                                ,"><" ,"‘/" ,"Z"};
                
                String result = "";
                s = s.toLowerCase();
                
                for(char c: s.toCharArray()) {
                        if(Character.isAlphabetic(c)) {
                                result += convertedChars[c - 'a'];
                        } else {
                                result += c;
                        }
                }
                
                return result;
        }

        public static void main(String[] args) {
                System.out.println(translateString("Java Concepts"));
        }
}
**************************************************

Thanks for your question. We try our best to help you with detailed answers, But in any case, if you need any modification or have a query/issue with respect to above answer, Please ask that in the comment section. We will surely try to address your query ASAP and resolve the issue.

Please consider providing a thumbs up to this question if it helps you. by Doing that, You will help other students, who are facing similar issue.

Add a comment
Know the answer?
Add Answer to:
Spell it out! Use the following Java concepts to compile the program below:   String myName =...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a Java program that uses the concepts below:   String myName = "Rick";     int length...

    Create a Java program that uses the concepts below:   String myName = "Rick";     int length = myName.length();     char firstChar = myName.charAt(0);     char secondChar = myName.charAt(1);     if (myName.equals("Jerry")) {       System.out.println ("Don't be a Jerry");   } Write a program that uses a METHOD to translate numbers (1-10) into their verbal counterparts. ex: 1 would be translated into "one" DO NOT use arrays or subStrings for this task!!! Sample output: Enter a String: 123 one two three

  • JAVA Applying the concept of method overloading, create, compile and run a Java program that calculates...

    JAVA Applying the concept of method overloading, create, compile and run a Java program that calculates and displays the result for each overload: Given int P = 30, double Q = 50.00, float R = 70.5 • First overload: return P + 1/3P • Second overload: return Q + 1/2Q • Third overload: return R + 1/4R Take screen captures of code and output. Program should illustrate method overloading (same method name), and appropriate use of classes, variable, and return...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • C++ Concepts: Single-Dimension Array Write a program, using 25 or fewer lines of code, to count...

    C++ Concepts: Single-Dimension Array Write a program, using 25 or fewer lines of code, to count each occurrence of each lower-case letter in a string. Start your program by declaring a character array, msg, with a size of 30 or greater. char msg[MAX]; The user should then type a text string into the array: cin.getline(msg, MAX); Your program should now report the number of each character (a-z) found in the array: a face at the beach a - 4 b...

  • Hi. This is a prototype of Java. The following Java program was developed for prototyping a...

    Hi. This is a prototype of Java. The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator). HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the...

  • Help with a question in Java: What is the output from the following program? public class...

    Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }

  • 12.22 Chapter 4: Encrypt Characters Simple Caesar Cipher challenge. You'll need to correct code to print...

    12.22 Chapter 4: Encrypt Characters Simple Caesar Cipher challenge. You'll need to correct code to print ciphertext character correctly. With offset of 3 the output should be ORIGINAL CHARACTERS A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ENCRYPTED CHARACTERS D E F G H I J K L M N O P Q R S T U V W X Y Z...

  • Edit, compile, and run the following programs on the UNIX shell: Write a program that takes...

    Edit, compile, and run the following programs on the UNIX shell: Write a program that takes in six commandline arguments and has four functions (described below) that use bitwise operators. The user should enter six space-separated commandline arguments: four characters (any ASCII character) followed by two integers. Anything else should print an error message telling the user what the correct input is and end the program. Convert the commandline input into "unsigned char" and "unsigned int" datatypes. Be careful with...

  • C++ program by netBeans java language Exercise #2: Write a java program that prompts the user...

    C++ program by netBeans java language Exercise #2: Write a java program that prompts the user to enter a sentence. The program has to find the print: a. the position of vowels in the sentence. b. the number of vowels in the sentence (A, a, U, u, E, e, 0, o, I, i) c. the number of characters as numbers or special characters (other than English letters a..z, A..Z). Hint: remember to ignore the spaces. Sample input-output: Enter the sentnse:...

  • Write a program that replace repeated three characters in a string by the character followed by 3...

    Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT