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
Which is the correct expansion of the term Internet? 
kirill115 [55]

Answer:

international network

Explanation:

8 0
4 years ago
Read 2 more answers
Which type of word processing programs enables us to include illustrations within the program?
bonufazy [111]

Answer:

C.  full featured

Explanation:

You need to make use of the full-featured version of the word processing programs to use the illustrations that are part of the program. And simple versions might not have that. By fully featured it means you need to have the license included or else you will be able to use it for a few days or a maximum of 3 months, and that is certainly not a good idea.

5 0
3 years ago
What would be the result of running the program below?list ← [ 1, 2, 3 ]APPEND ( list, 5 )INSERT ( list, 4, 4 )REMOVE ( list, 5
Korvikt [17]

Answer:

.b. The program would display the list [1, 2, 3, 4]

Explanation:

list ← [ 1, 2, 3 ]: this would create a list of [1, 2, 3]

APPEND ( list, 5 ): this would append 5 to the existing list and the output would be [1, 2, 3, 4, 5]

INSERT ( list, 4, 4 ): this would insert 4 at index 4 of the list and we would have the list to be [1, 2, 3, 5, 4]. The list index counting is from zero.

REMOVE ( list, 5 ): this would remove the occurrence of 5 from the list and the resulting list is [1, 2, 3, 4]

DISPLAY ( list ): this would display the list which is [1, 2, 3, 4]

7 0
3 years ago
Dereck works for long hours on his computer. He frequently experiences physical strain by the end of the day because he does not
rjkz [21]
<span>keeping hands and wrists straight while typing</span>
3 0
3 years ago
Read 2 more answers
How does using wind energy relate to our world today?
Drupady [299]

Answer:

Explanation:

Because the electricity from wind farms is sold at a fixed price over a long ... and wind is now the largest source of renewable power in the United States. ... by the heating of the atmosphere by the sun, the rotation of the Earth, and the ... Wind power must still compete with conventional generation sources on a cost basis.

8 0
3 years ago
Read 2 more answers
Other questions:
  • A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-lif
    11·1 answer
  • Magnetic energy can build up in the atmosphere of the sun. When this energy is finally released, it is 10 million times greater
    15·1 answer
  • To increase usability, take care to place important content, such as logos, names, CTAs, and major links, ______ of potential sc
    11·1 answer
  • Explain about RDBMS. Include advantages/ disadvantages. Compare DBMS vs RDBMS. Explain about Oracle as well.
    14·2 answers
  • Malcolm is part of a team developing a new smartphone app to track traffic patterns. Because team members are located throughout
    12·1 answer
  • Cable television, as well as some networks, uses ________ cable.
    10·1 answer
  • What symbol do we use to denote a character?
    9·2 answers
  • Assume that passwords are selected from four-character combinations of 26 alphabeticcharacters. Assume that an adversary is able
    11·1 answer
  • Adobe Indesign project 4 museum indesign file. The instructions are 70 pages long I cant sit still long enough to read them
    11·1 answer
  • Sarah is a detall-oriented programmer. While testing her program, what other skill would she have to apply in order to detect al
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!