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
Why is manual coding the best way to learn HTML?
Stels [109]

Answer:

It helps to put the code in to your working memory and you will have a greater ability to problem solve.

Explanation:

If your just a beginner, then writing the code out your self will help you learn what each line means. Also, you will see the effects that each line has. Of course, this is really dependent on how much code you've written before and how much code your dealing with.

5 0
2 years ago
How do you use a Hard Drive
Ray Of Light [21]
Plug it into pc and wahlah
3 0
2 years ago
Read 2 more answers
The read/write heads of a hard disk gently rest on the hard disk platters in order to read and write the data.
noname [10]
The answer is FALSE because the interior of commercial Hard disk drive is with stack of magnetic disks (platters) containing the user’s data and a rotating arm supporting the magnetic heads. The rotating arm is moved by the torque generated by a voice coil motor (VCM) mounted at one end of the arm. Data read/write operations rely on the capability of the governing unit of the HDD to maintain the magnetic read/write heads as close as possible to center of the desired track. Typically, reliability of data reading and writing is guaranteed when the head is kept within 5% of the track pitch from the track center. This means that the accuracy required for the head positioning is in the range of a few tens of nanometers.
6 0
3 years ago
The windows troubleshooting utility that identifies and eliminates nonessential files is called _____.
Virty [35]
I think it is Defragment
8 0
3 years ago
Read 2 more answers
Which set of symbols encloses an if-then code block? Choose the best answer.
Colt1911 [192]

Here's some code that might help, assuming that you are using JavaScript.

e = "Hello"

if(e === "Hello"){

    alert(":D")

}else{

    console.log("Um.")

}

I think that the answer is curly brackets.

8 0
3 years ago
Other questions:
  • Plz answer me will mark as brainliest ​
    7·2 answers
  • When a speaker is finished talking, you should allow for _____.
    14·2 answers
  • Select
    14·1 answer
  • Choose all items that represent characteristics of an HTML element. used to include additional information in an attribute consi
    15·1 answer
  • You can combine the algorithms for converting between infix to postfix and for evaluating postfix to evaluate an infix expressio
    13·1 answer
  • Sebutkan beberapa contoh peralatan komunikasi zaman dahulu beserta dengan keterangannya!
    14·1 answer
  • Hewo everyone look at me I look ugly don't I<br>​
    6·2 answers
  • Which of the following substances increases in quantity during repititive muscle contraction during oxygen deficti ?
    11·1 answer
  • The goal of this project is to become familiar with basic Python data processing and file usage. By the end of this project, stu
    8·1 answer
  • Select one Layer 2 or wireless WAN technology presented in Lesson 3. Elaborate on its characteristics, pros and cons, and common
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!