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
If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every pla
sergiy2304 [10]

If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every place you copy it to, the way to reference the cell? is known to be $C$2.

<h3>What is a cell reference in Excel?</h3>

A cell reference is known to be called a cell address and this is seen as a make up of a column letter and also those of  row number that tells a cell on a worksheet.

Hence, If you are referencing cell (C2)in Excel and want to be able to copy the formula and keep using the data in cell C2 in every place you copy it to, the way to reference the cell? is known to be $C$2.

Learn more about cell referencing from

brainly.com/question/19035038

#SPJ1

8 0
2 years ago
You hear someone make the following comment: "A blueprint is a design for a house. A carpenter can use the blueprint to build th
max2010maxim [7]

Answer:

The answer is "classes are the blueprints"

Explanation:

According to the class definition, it is a collection of data members and member methods, in which all the data members can't return any value, and member methods or functions return a value.

  • In this question, the carpenter uses the blueprint to build the house, if he uses class and object model.
  • This model also known as an entity blueprint, which sets the properties and functions with an object type.
4 0
4 years ago
Select the correct answer.
Triss [41]

Answer:

b or d

Explanation:

3 0
3 years ago
Int main() { printf("%d\n", getOddPositionedDigits(89201)); printf("%d\n", getOddPositionedDigits(-123)); printf("%d\n", getOddP
Luba_88 [7]

Int Main () dvaunoax o]inxoo jnjn os'i

Explanation: Int Main KIcqvd[uo v[ionon

hxbc ;zzzzzzzzzzzczjHiuhqvzbp;'k

3 0
3 years ago
PLEASE HELP!!! THIS IS DUE TODAY!! WIL MARK BRAINLIEST!!<br> What value does Netflix bring to people
ki77a [65]

Answer:

it allows people to distract themselves from the things going on, it also entertains people

Explanation:

hope this helps

7 0
3 years ago
Read 2 more answers
Other questions:
  • Question: when using a line graph, why is it important to only graph 1-3 series of data?
    8·1 answer
  • Which of the following is a reason photographing animals can be difficult?
    9·2 answers
  • How it print media used? ​
    9·1 answer
  • Which of the following is a dynamic lot-sizing technique that calculates the order quantity by comparing the carrying cost and t
    10·1 answer
  • What browser is included with windows?
    7·1 answer
  • While technology has impacted many aspects of marketing. it has had little effect on database marketing
    5·2 answers
  • We have the following class:
    6·1 answer
  • Write a method that takes in a String and returns a new
    15·1 answer
  • What would be the greatest tool for emphasis? (video class)
    9·1 answer
  • Here’s my last question
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!