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
Anna [14]
3 years ago
14

In this assignment, you are provided with working code that does the following: 1. You input a sentence (containing no more than

50 characters). 2. The program will read the sentence and put it into an array of characters. 3. Then, it creates one thread for each character in the sentence. 4. The goal of the program is to capitalize each letter that has an odd index. The given program actually does this, but lacks the synchronization of the threads, so the output is not correct. You will need to provide the synchronization using mutex locks. Specifically, you are to (1) declare the mutex lock, (2) initialize the mutex lock, (3) lock and unlock the mutex lock at an appropriate location that results in the code working as expected, and (4) destroy the mutex lock. Be sure to place the mutex locks so that your program works correctly every time. Do not remove code or functions – you are to add the synchronization pieces only.
Computers and Technology
1 answer:
Olegator [25]3 years ago
4 0

Answer:

The code is given below,

import java.io.File;

import java.io.FileInputStream;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class SentenceUtilsTest {

public static void main(String[] args) {

List<SentenceUtils> sList = new ArrayList<SentenceUtils>();

try{

File file = new File(args[0]);

Scanner scanner = new Scanner(new FileInputStream(file));

while(scanner.hasNextLine()){

String sent = scanner.nextLine();

if(sent.trim().length() > 0){

SentenceUtils sUtils = new SentenceUtils(sent);

sList.add(sUtils);

}

}

System.out.println("File that was read:" + args[0]);

System.out.println("File contains " + sList.size() + " sentences.\n");

System.out.println("Sentences reports:\n");

for(int line = 0; line < sList.size(); line++){

System.out.println("Sentences " + line +";");

System.out.println(sList.get(line).getSentence());

SentenceUtils lineText = sList.get(line);

String[] tokens = lineText.getTokens();

for(int id = 0; id < tokens.length; id++){

System.out.println(id+":"+tokens[id]);

}

String[] shingles = lineText.getShingles();

for(int id = 0; id < shingles.length; id++){

if(shingles[id] != null){

System.out.print(shingles[id]+" ");

}

}

System.out.println("\n");

}

}catch(Exception ex){

ex.printStackTrace();

}

}

}

package sentenceutils;

import java.util.ArrayList;

import java.util.List;

public class SentenceUtils {

private String sentence;

private String[] tokens;

private String[] shingles;

public SentenceUtils(String s){

this.sentence = s;

generateTokens();

generateShingles();

}

private void generateShingles() {

List<String> shinglesList = new ArrayList<String>();

for (int index=0; index < sentence.length()-1; index++) {

shinglesList.add( sentence.charAt(index) +""+sentence.charAt(index+1) );

}

shingles = new String[sentence.length()];

shinglesList.toArray(shingles);

}

private void generateTokens() {

tokens = sentence.split(" ");

}

public String getSentence() {

return sentence;

}

public String[] getTokens() {

return tokens;

}

public String[] getShingles() {

return shingles;

}

}

You might be interested in
You can access various sites on the WWW by using hyperlinks or by______. A. entering a key word for your search B. following dir
saw5 [17]
The correct answer is C
8 0
2 years ago
Read 2 more answers
Explain why there are fundamental ideas of software engineering that apply to all types of software systems.
olasank [31]

Solution:

Because of all software systems have common quality attributes, including  

Fundamental software engineering activities.  The four basic process activities of specification, development, validation and evolution are organized differently in different development processes.  The software is implemented either by developing a program or programs or by configuring an application system. Such that at they (Software engineer) have been made keeping in mind project development. They hence, apply to all software systems and even non software systems. They are the fundamentals for any kind of project development.

Thus this is the required answer..


5 0
3 years ago
Arrange the steps involved in natural language generation.
Firdavs [7]

Answer:

1. accessing content from some knowledge base.

2. picking words and connecting them to form sentences.

3. setting the tone and style of the sentence.

4. mapping the sentence plan into sentence structure.

Explanation:

Natural language generation can be defined as a part of artificial intelligence (AI) which typically involves developing responses by an AI in order to enable the computer engage in a useful conversation.

This ultimately implies that, the computer has to generate meaningful data (phrases and sentences) from the internal database.

Basically, the steps involved in natural language generation in a chronological order are listed below;

1. Text planning: accessing content from some knowledge base.

2. Picking words and connecting them to form sentences

3. Sentence planning: setting the tone and style of the sentence.

4. Text realization: mapping the sentence plan into sentence structure.

4 0
2 years ago
Suppose you're trying to remove the clamp from a ground strap that's connected to a battery. The clamp won't come loose. Which o
Mekhanik [1.2K]
The answer would be B.
5 0
3 years ago
Read 2 more answers
Most search engines provide specific pages on which you can search for____ and
vazorg [7]

Answer: c

Explanation: a

7 0
2 years ago
Read 2 more answers
Other questions:
  • Rori is looking for a way to interact with others while increasing her stamina. Which community resource would be least helpful
    13·1 answer
  • When you declare a string data type, you are actually creating an object from the?
    5·1 answer
  • The ____ aggregate function finds the largest value
    10·1 answer
  • Using python:
    10·1 answer
  • What type of undocumented yet benign hidden feature launches after a special set of commands, key combinations, or mouse clicks?
    15·1 answer
  • Which type of loan is based on financial need
    6·1 answer
  • The most commnonly used OS is ___.<br> MS-DOS<br> Windows<br> Mac<br> Linux
    8·1 answer
  • Consider the following class definition.
    7·1 answer
  • A class is a type of object that defines the format of the object and the actions it can perform. True False
    14·1 answer
  • When a computer is infected by a virus, _______.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!