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
AVprozaik [17]
3 years ago
13

Write a program that replaces words in a sentence. The input begins with an integer indicating the number of word replacement pa

irs (original and replacement) that follow. The next line of input begins with an integer indicating the number of words in the sentence that follows. Any word on the original list is replaced. Ex: If the input is: 3 automobile car manufacturer maker children kids 15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one. then the output is: The car maker recommends car seats for kids if the car doesn't already have one. You can assume the original words are unique. For coding simplicity, follow each output word by a space, even the last one. Hint: For words to replace, use two vectors: One for the original words, and the other for the replacements. Your program must define and call the following function that returns index of word's first occurrence in wordList. If not found, then the function returns -1. int FindWordInWordList(vector wordList, string wordToFind)
Computers and Technology
1 answer:
kramer3 years ago
3 0

Answer: provided in the explanation segment

Explanation:

This is the code to run the program:

CODE:  

//Input: 3 automobile car manufacturer maker children kids

  //15 The automobile manufacturer recommends car seats for children if the automobile doesn't already have one.

  import java.util.Scanner;

  public class LabProgram{

  public static int findWordInWordList(String[] wordList, String wordToFind, int numInList) {

          for (int i = 0; i < numInList; i++) {

              if (wordList[i].equals(wordToFind)) {

                  return i;

              }

          }

          return -1;

      }

      public static void main(String[] args) {

          Scanner scan = new Scanner(System.in);

          String[] original_String = new String[20];

              String[] modified_String = new String[20];

          int numInList = scan.nextInt();

          for (int i = 0; i < numInList; i++) {

              original_String[i] = scan.next();

              modified_String[i] = scan.next();

          }

          int num_Of_Words = scan.nextInt();

          String[] words_To_Replace = new String[num_Of_Words];

          for (int i = 0; i < num_Of_Words; i++) {

              words_To_Replace[i] = scan.next();

          }

          int indx;

          for (int i = 0; i < num_Of_Words; i++) {

              indx = findWordInWordList(original_String, words_To_Replace[i], numInList);

              if (indx != -1)

                  words_To_Replace[i] = modified_String[indx];

          }

          for (int i = 0; i < num_Of_Words; i++)

              System.out.print(words_To_Replace[i] + " ");

          System.out.println();

      scan.close();

      }

  }

cheers i hope this helps!!!!1

You might be interested in
What are Important points to include about preventing the download of malware?
Natasha2012 [34]

Check if it’s a viable site, the browser will usually warn you if the site or file as to what you’re downloading from is dangerous.

7 0
3 years ago
How should work be allocated to the team in a Scrum project?
Mkey [24]

Answer:

In a Scrum project, the work or the tasks are not allotted specifically. The Scrum Master is not allowed to assign tasks to the team members under any circumstance. Once the client provides the details regarding their requirements in detail, the tasks are distributed based on the expertise and skills of the employee.

Explanation:

4 0
3 years ago
Which of the following is a default letter assigned for the primary hard drive
d1i1m1o1n [39]

C

.............

When hard disk drives became standard in most PCs in the later 1980s, since the first two letters were already commonly used for these floppy drives, they logically labeled the third storage device “C”, even though it now tended to be the main storage medium for the computer, including usually containing the operating system.

6 0
3 years ago
Read 2 more answers
A ___________ is the smallest unit in a written language.
Delvig [45]
A. string? maybee its a string of units


8 0
3 years ago
Read 2 more answers
What type of encryption is this "1d83ad29cf19ff399445aff3a0da74d9"
bija089 [108]

Due to the length of the hash I'm going to say it's MD5

7 0
2 years ago
Other questions:
  • What does rwd stand for?
    8·2 answers
  • How do you read a column
    8·1 answer
  • Which fingers should you use to type the reach keys?
    12·1 answer
  • Which of the following is not an advantage of using asynchronous data transmission
    15·1 answer
  • A writing team wants to present the six-month sales figures for its company's 14 sales representatives in a report. Because mana
    11·1 answer
  • IDE devices require the use of a controller mounted on the motherboard. True False
    14·2 answers
  • A ________ is a self-contained program that spreads through a computer network by exploiting security holes in the computers con
    9·1 answer
  • "The ability to assign system policies, deploy software, and assign permissions and rights to users of network resources in a ce
    7·1 answer
  • What is the largest value that can be represented by 6 binary digits? .
    5·1 answer
  • Name four successful conversions to an electronic health record system in a medical facility
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!