answer.
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]
2 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]2 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
Zoey has brought her computer in for servicing. When she dropped off her computer, she mentioned that her computer will sometime
galina1969 [7]

Answer:

Option (B) Overheated CPU

Explanation:

  • The above problems mentioned are due to the problem with the CPU.
  • Overheated CPU can result into freezing the computer and unexpected rebooting.
  • CPU stands for Central Processing Unit and is responsible for all the instabilities in the hardware parts of the computer.
  • So, option (b) is true.
  • A Network Card is responsible for connecting the computer to the internet. It also has other names like Ethernet Card. A bad Network Card results in problems with the internet and network connections but not the above problems. So, option (A) is false.
  • UPS is Uninterrupted Power Supply. It is an external power device to provide the power supply to the computers in case of emergencies to not shut down the computer instantaneously. The above problems are not likely to be the caused by the failed UPS. So, option (C) is false.
  • Drive is a hardware device to store information. It can be removable drive (optical drives like CDs, DVDs ) or non removable like ( Hard Disk Drive ). A failed drive results in problems with the storing information. The above problems are not associated with it. So, option (D) is also false.
6 0
2 years ago
Read 2 more answers
Disk scheduling algorithms in operating systems consider only seek distances, because Select one: a. modern disks do not disclos
Sergeu [11.5K]

Answer:

a. modern disks do not disclose the physical location of logical blocks.

Explanation:

In modern disks, the disk scheduling algorithms are built in the disk drive. It is difficult for operating system to schedule for improved rotational latency. All scheduling algorithms are forced to behave the same because operating system may have constraints. Disks are usually accessed in physical blocks. Modern disks put more electronic controls on the disk.

4 0
2 years ago
What language(s) must be used to display a bare-minimum web page?
Reil [10]

Answer: Hyper Text Markup Language (HTML)

Explanation:  

Computers use language to communicate, just like people do and the way that computers communicate with the internet is through a language that is called Hyper Text Markup Language/ HTML

Hyper Text is the process of linking objects to each other, so that when one object is clicked the linking object can be viewed. Hyper Text Markup Language was created by Tim burners in 1990


8 0
2 years ago
Read 2 more answers
Which statements describe best practices for aligning text? check all that apply
kiruha [24]

Answer: *use the last column for text with multiple lines.

*use an indent marker to indent the first line of a paragraph.

*use a table if text in multiple columns have multiple lines.

Explanation:

5 0
2 years ago
Read 2 more answers
Enter a formula in cell G5 that calculates the difference between the attendance totals for 2018 and 2017. Copy the formula to t
Allushta [10]
This is done by a very simple formula: the only thing you need to type is =x-y where x is the cell that contains the total of 2018 and y being the cell that contains the total for 2017. If both are numeric values you can use the formula = A1-B1 and get your result. Your <span>cells don't have to be in the same order as your formula.</span>
4 0
2 years ago
Other questions:
  • Which table style option is useful to display aggregated data when it is checked? total row filter button last column header row
    8·1 answer
  • Computer hardware had been designed to run a single operating system and a single app, leaving computers vastly underutilized. o
    15·1 answer
  • Explain why companies design products with a planned obsolescence
    14·1 answer
  • Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
    7·1 answer
  • Describe the Say It, Cover It, Resay It method.
    14·2 answers
  • Assume that the population of Mexico is 128 million and that the population increases 1.01 percent annually. Assume that the pop
    7·1 answer
  • Use the following data definitions data myBytes BYTE 10h,20h,30h,40h myWords WORD 3 DUP(?),2000h myString BYTE "ABCDE" What will
    9·1 answer
  • Create a program that includes a function called toUpperCamelCase that takes a string (consisting of lowercase words and spaces)
    9·1 answer
  • Write a program that simulates the functionality of a vending machine having the following characteristics:• The vending machine
    11·1 answer
  • Nathan would like to save his PowerPoint presentation as a video that can be replayed easily on any device at full quality. Whic
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!