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
The function below takes a single parameter number_list which is a list that can contain integers and floats. Complete the funct
Andreas93 [3]

Answer:

  1. def getLargest(number_list):
  2.    new_list = []
  3.    for x in number_list:
  4.        if(isinstance(x, int)):
  5.            new_list.append(x)
  6.    largest = max(new_list)
  7.    return largest  

Explanation:

Firstly, create a function <em>getLargest()</em> that take one input parameter, <em>number_list</em>.

The function will filter out the float type number from the list by using <em>isinstance() </em>method (Line 5). This method will check if a current x value is an integer. If so, the x value will be added to <em>new_list</em>.

Next, use Python built-in <em>max</em> function to get the largest integer from the <em>new_list </em>and return it as output.

6 0
4 years ago
Difference between softcopy and hardcopy​
Rashid [163]

A hard copy is the digital file, stored in a device and was printed out. A soft copy is the electronic version NOT PRINTED. It is showcased digitally (through a phone, computer, flash drive etc)

3 0
3 years ago
Read 2 more answers
Someone say crackhead
Ghella [55]

Answer:

................. crackhead

6 0
3 years ago
Read 2 more answers
Which of the actions below will not create more room on your hard drive?
slavikrds [6]
A. defragging your hard drive
4 0
3 years ago
What are the basic Mouse actions called and how are they executed
Nata [24]
The left side is a shortcut for 'Enter' the small wheel in the middle is used to scroll your view of the object,The right is used to intialize options pop-up to edit or initiate commands of the intended target


6 0
3 years ago
Other questions:
  • The binary search algorithm ________. will have a maximum number of comparisons equal to the number of elements in the array wil
    7·1 answer
  • What is a relationship between a object and a class?
    6·1 answer
  • PLEASE HELPPPPPPP
    15·1 answer
  • Choose all that apply.
    6·2 answers
  • 2. Which the following may be a reason for giving a Page Quality (PQ) rating og Highest? Select all that apply (True or False)
    14·1 answer
  • Word processing software programs can run on smartphones.<br> True<br> Or <br> False
    6·1 answer
  • What is a Joint Staff approved, standardized communications link that is suitable for the transmission of digital information an
    5·1 answer
  • Haya would like to complemely delete Slide 11 from her presentation so that slides 12–16 become slides 11-15. What is
    9·1 answer
  • What are the peripherals of a computer ​
    12·1 answer
  • Electronic hacking and illegal trespassing for the purposes of acquiring a competitor’s proprietary information is considered.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!