1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
exis [7]
3 years ago
7

Write a program that prompts for a line of text and then transforms the text based on chosen actions. Actions include reversing

the text and converting the text to leet-speak. You may be able to imagine extending to other actions such as a pig-latin translator, or encoding or decoding a secret message. Turn in the version specified here before extending Welcome to the Text Converter Available Actions 1337) convert to 1337-speak rev) reverse the string quit) exit the progranm Please enter a string: Hello cs 200. Action (1337, rev, quit): rev 002 Sc olleH Action (1337, rev, quit): reverse again Unrecognized action. 002 Sc olleH Action (1337, rev, quit): rev ?? 11 CS 200. Action (1337, rev, quit): quit See you next time!
Engineering
1 answer:
nlexa [21]3 years ago
7 0

Answer:

public class TextConverterDemo

{

//Method definition of action1337

public static String action1337(String current)

{

//Replace each L or l with a 1 (numeral one)

 current = current.replace('L', '1');

 current = current.replace('l', '1');

 

 //Replace each E or e with a 3 (numeral three)

 current = current.replace('E', '3');

 current = current.replace('e', '3');

 //Replace each T or t with a 7 (numeral seven)

 current = current.replace('T', '7');

 current = current.replace('t', '7');

 //Replace each O or o with a 0 (numeral zero)

 current = current.replace('O', '0');

 current = current.replace('o', '0');

 

//Replace each S or s with a $ (dollar sign)

 current = current.replace('S', '$');

 current = current.replace('s', '$');

 return current;

}

//Method definition of actionReverse

//This method is used to reverses the order of

//characters in the current string

public static String actionReverse(String current)

{

 //Create a StringBuilder's object

 StringBuilder originalStr = new StringBuilder();

 //Append the original string to the StribgBuilder's object

 originalStr.append(current);

 //Use reverse method to reverse the original string

 originalStr = originalStr.reverse();

 

 //return the string in reversed order

 return originalStr.toString();

}

//Method definition of main

public static void main(String[] args)

{

    //Declare variables

 String input, action;

 

 //Prompt the input message

 System.out.println("Welcome to the Text Converter.");

 System.out.println("Available Actions:");

 System.out.println("\t1337) convert to 1337-speak");

 System.out.println("\trev) reverse the string");

 System.out.print("Please enter a string: ");

   

 //Create a Scanner class's object

 Scanner scn = new Scanner(System.in);

 

 //Read input from the user

 input = scn.nextLine();

 do

 {

  /*Based on the action the user chooses, call the appropriate

   * action method. If an unrecognized action is entered then

   * the message "Unrecognized action." should be shown on a

   * line by itself and then the user is prompted again just

   * as they were when an action was performed.

   * */

  System.out.print("Action (1337, rev, quit): ");

  action = scn.nextLine();

  if (action.equals("1337"))

  {

   input = action1337(input);

   System.out.println(input);

  } else if (action.equals("rev"))

  {

   input = actionReverse(input);

   System.out.println(input);

  } else if (!action.equals("quit"))

  {

   System.out.println("Unrecognized action.");

  }

 } while (!action.equals("quit"));

 System.out.println("See you next time!");

 scn.close();

}

}

You might be interested in
13. Write a function which is passed two strings. The function creates a new string from the two original strings by copying one
attashe74 [19]

Answer:

I am writing the code in C++. Let me know if you want the program in some other programming language.

#include <iostream>  // includes header file for input output functions

using namespace std;     //to identify objects like cin cout

string CopyStrings(string string1, string string2)  

{   string newString = "";    

   for (int loop = 0; loop < string1.length() ||  

                   loop < string2.length(); loop++)      {      

       if (loop < string1.length())  

           newString += string1[loop];          

       if (loop < string2.length())  

           newString += string2[loop];      }  

   return newString;   }  

int main()  

{   string stringA = "ace";  

   string stringB = "bdf";  

   cout << CopyStrings(stringA, stringB);   }

Output:

abcdef

Explanation:

The function CopyStrings() function takes two strings i.e. string1 and string2 as parameters to copy characters from both the string one character from each.

The newString variable stores the new string after copying characters from both strings string1 and string2.

Then the for loop starts which has a variable loop which is an index variable that traverses through both the strings stored in string1 and string2. The loop continues to execute until it moves through entire length of string1 and string2 which means it copies all the characters from both string1 and string2. length() is used here which returns length of the string1 and string2.

If statement in the for loop checks the character that loop (index) variable is pointing to is less than the string1 length which means it checks each character stored in string1. For example if string1 contains "ace" and loop variable is moving through the string and is currently at "a" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character a into the newString variable.

Next If statement checks character that loop variable is pointing to is less than the string2 length which means it checks each character stored in string2. For example if string2 contains "bdf" and loop variable is moving through the string and is currently at "b" then this condition is true. If the condition evaluates to true then the body of if statement is executed. The next statement stores that character b into the newString variable.

Then the second iteration starts which again first stores the next character i.e. c from string1 into newString and then stores next character i.e d from string2 into newString.

Then the third iteration starts which again first stores the next character i.e. e from string1 into newString and then stores next character i.e f from string2 into newString.

Then the loop breaks as the loop variable reaches end of both the string1 and string2.

return newString will return the copied string into the output screen which is abcdef.

The screenshot of code along with output is attached.

3 0
3 years ago
Technician a says that if a tapered roller bearing is adjusted to loose
Effectus [21]
The technician is true
5 0
2 years ago
Air flows through a 0.25-m-diameter duct. At the inlet the velocity is 300 m/s, and the stagnation temperature is 90°C. If the M
Naddika [18.5K]

Answer:

a. 318.2k

b. 45.2kj

Explanation:

Heat transfer rate to an object is equal to the thermal conductivity of the material the object is made from, multiplied by the surface area in contact, multiplied by the difference in temperature between the two objects, divided by the thickness of the material.

See attachment for detailed analysis

7 0
3 years ago
Heat is transferred at a rate of 2 kW from a hot reservoir at 800 K to a cold reservoir at 300 K. Calculate the rate at which th
andre [41]

Answer:

4.17x10^-3 kW/K

Explanation:

Detailed explanation and calculation is shown in the image below

6 0
3 years ago
To find the reactance XLXLX_L of an inductor, imagine that a current I(t)=I0sin(ωt)I(t)=I0sin⁡(ωt) , is flowing through the indu
Sophie [7]

Answer:

V(t) = XLI₀sin(π/2 - ωt)

Explanation:

According to Maxwell's equation which is expressed as;

V(t) = dФ/dt ........(1)

Magnetic flux Ф can also be expressed as;

Ф = LI(t)

Where

L = inductance of the inductor

I = current in Ampere

We can therefore Express Maxwell equation as:

V(t) = dLI(t)/dt ....... (2)

Since the inductance is constant then voltage remains

V(t) = LdI(t)/dt

In an AC circuit, the current is time varying and it is given in the form of

I(t) = I₀sin(ωt)

Substitutes the current I(t) into equation (2)

Then the voltage across inductor will be expressed as

V(t) = Ld(I₀sin(ωt))/dt

V(t) = LI₀ωcos(ωt)

Where cos(ωt) = sin(π/2 - ωt)

Then

V(t) = ωLI₀sin(π/2 - ωt) .....(3)

Because the voltage and current are out of phase with the phase difference of π/2 or 90°

The inductive reactance XL = ωL

Substitute ωL for XL in equation (3)

Therefore, the voltage across inductor is can be expressed as;

V(t) = XLI₀sin(π/2 - ωt)

3 0
3 years ago
Other questions:
  • The smallest crystal lattice defects is a) cracks b) point defects c) planar defects d) dislocations.
    11·1 answer
  • In a semiconductor manufacturing process, three wafers from a lot are tested. Each wafer is classified as pass or fail. Assume t
    15·1 answer
  • Wiring harnesses run
    12·1 answer
  • Is an ideal way for a high school student to see what an engineer does on a typical day but does not provide a hands-on experien
    9·2 answers
  • Consider a step pn junction made of GaAs at T = 300 K. At zero bias, only 20% of the total depletion region width is in the p-si
    11·1 answer
  • Describe a gear train that would transform a counterclockwise input rotation to a counterclockwise output rotation where the dri
    13·1 answer
  • PLEASE HELP WITH THIS ASAP! Thanks
    6·1 answer
  • Me ayudas plis noce ​
    14·1 answer
  • A torque T 5 3 kN ? m is applied to the solid bronze cylinder shown. Determine (a) the maximum shearing stress, (b) the shethe 1
    10·1 answer
  • What is included in the environmental impact assessment process, such as the use of geographic information systems?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!