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
Consider what fact-finding techniques you would use to identify the important facts needed to develop a database system. Please
8090 [49]

Answer:

Examples of Fact-finding techniques includes:

  1. Prototyping
  2. Questionnaires
  3. Research and sites visit
  4. Interviews

Explanation:

It is important to note that a database system is a tool that allows users to define, create, maintain, and control access to a collection of logically related data and description of these data, designed to meet the information needs of an organization.

<u>Prototyping </u>

<em>Advantage:</em>  enables testing and understanding of the system in advance before final implementation of solution, while requiring less time for research.

<em>Disadvantage:</em> Training and Development cost consumes resources.

<u>Research and site visit </u>

<em>Advantage :</em> better time management if the problem has been researched upon before.

<em>Disadvantage:</em> appropriate permission is often needed before using research materials.

<u> Questionnaires </u>

<em>Advantage: </em>This technique is not expensive, and responses can be calculated and analysed quickly.

<em>Disadvantage:</em> There may be Incomplete answers received from users and body language of user cannot be observed.

<u>Interviews</u>

<em>Advantage:</em> The body language of interviewees is been perceived.

<em> Disadvantage: </em>Interviewing is time consuming and costly.

3 0
3 years ago
In addition to the decimal number system, the number systems used most often in PLC operationand programming are ________.
otez555 [7]

Answer: PLC uses:

1. Decimal Number system

2. Binary Number system.

3. Octal Number system.

4. Hexadecimal Number system.

5. Binary Coded Decimal Number system.

6. Negative Number system.

7. Number Conversations.

Explanation: The other numbers the Programmable Logic Controller(PLC) uses aside the decimal number system are:

1. Binary Number system.

2. Octal Number system.

3. Hexadecimal Number system.

4. Binary Coded Decimal Number system.

5. Negative Number system.

6. Number Conversations.

7 0
3 years ago
Zoe wants to use an image file that will allow her to preserve all of the original
liberstina [14]

Answer:

DOC FILES OR MP3s

Explanation:

DOC FILES AND MP3s BEACUSE THEY HAVE BETTER STORGE TO HOLD THE IMPORTANT FILES AND WORK THAT U DO AND SAVE

8 0
2 years ago
True or False(T or F): Point-and-shoot cameras have only 1 lens. *
liq [111]

Answer:

True

Explanation:

Technically speaking they only have one.

7 0
3 years ago
Case 2-2 Jack has a computer at home that he uses to access the Internet, store and edit personal photos, and create and edit do
bekas [8.4K]

Answer:

Check button under error checking

Explanation:

Under the Tools tab there are two options:

Error checking and Optimize and defragment drive option.

clicking the check button with administrative permission under error checking option will examine the hard drive for errors.

3 0
3 years ago
Other questions:
  • Brenda's working on improving a Google Search Ads quality score so it potentially gets a better ad rank and performs better in t
    9·1 answer
  • What is the purpose of the chart feature in word?
    15·1 answer
  • A tornado may be approaching if you observe which of the following?
    15·1 answer
  • The_provides access to the internet may also be internal​
    9·1 answer
  • Mathematical expression that might link numbers in cells
    14·1 answer
  • C:\windows\system32\drivers\etc\protocol is an example of a file ________. select one:
    5·1 answer
  • Do you agree that technology can be used to commit acts of violence ? Explain why or why not
    11·1 answer
  • Look at the network topology. What will happen with the other computers if the computer breaks at the RED X?
    8·1 answer
  • Ask the user to input a word. Then, print the first letter, the last letter, and the length of the word on the same line with no
    6·1 answer
  • PLEASE HELP FIRST ONE TO ANSWER WILL GET BRAINLIEST!!
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!