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
faust18 [17]
3 years ago
5

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create a new Java application called "LetterCount" (without the quotation marks) according to the following guidelines. You are going to write a program that reads a txt file and reports what the most common letter in a different txt file. The program needs to count all the letters so that lowercase letters are counted the same way as uppercase letters. For example, A and a would count towards the same letter. A sample outline is: //Establish fileName, the String that is "data.txt" //Go through file and count the amount of letters in an array //Find the index of the largest value //Determine all the letters that were used the most and store as a Character ArrayList
Computers and Technology
1 answer:
Mars2501 [29]3 years ago
8 0

Answer:

See explaination

Explanation:

// LetterCount.java

import java.io.File;

import java.io.IOException;

import java.io.PrintWriter;

import java.util.NoSuchElementException;

import java.util.Scanner;

public class LetterCount {

public static void main(String[] args) {

// setting up a Scanner to read from keyboard

Scanner scanner = new Scanner(System.in);

try {

// asking and reading input file name

System.out.print("Enter name of input file: ");

String file = scanner.nextLine();

// reinitializing scanner to read from input file. this will throw

// file not found exception if file is not found.

scanner = new Scanner(new File(file));

// opening a file writer to create and write into output.txt file

PrintWriter writer = new PrintWriter(new File("output.txt"));

// creating a String containing all 26 alphabets

String alphabet = "abcdefghijklmnopqrstuvwxyz";

// creating an array containing 26 integers, all initialized to 0

int counts[] = new int[26];

// looping through the file

while (scanner.hasNext()) {

// reading next line, converting to lower case

String word = scanner.next().toLowerCase();

// looping through each character in current word

for (char c : word.toCharArray()) {

// finding index of c in alphabet

int index = alphabet.indexOf(c);

// if c is an alphabet, the index value will not be -1

if (index != -1) {

// incrementing counter at index position

counts[index]++;

}

}

}

// closing input file

scanner.close();

int largestCount = 0; // to store largest count of a character

String mostCommon = ""; // to store the character(s) that occur the

// most

// looping through counts array, finding the largest value

for (int i = 0; i < counts.length; i++) {

if (counts[i] > largestCount) {

// updating largestCount and mostCommon

largestCount = counts[i];

mostCommon = alphabet.charAt(i) + "";

} else if (counts[i] == largestCount) {

// same largest count, appending to mostCommon string

mostCommon += " " + alphabet.charAt(i);

}

}

// writing results to output file

writer.println("The most common letter(s): " + mostCommon);

writer.println("Count of occurrances: " + largestCount);

// closing file, saving changes, alerting user

writer.close();

System.out

.println("done! please check output.txt file for results.");

} catch (IOException e) {

// will be executed when the input/output file cant be opened or

// found, or if there is an error while reading the file

System.out.println(e.getMessage());

} catch (NoSuchElementException e) {

// will occur when there is no input provided for input file name.

System.out.println("No input!");

}

}

}

You might be interested in
Three positive impacts of computer technology in our society.​
Contact [7]

Explanation:

1. it has resulted into the manufacturing of vehicles , trains etc

2. 9through computer technology satellites have been invented to boost education through the use of Internet

3. it has improved agriculture by manufacturing machinery such as tractors, ploughs etc

7 0
3 years ago
Read 2 more answers
What are some consequences of internet addiction​
fenix001 [56]

Answer:

<em>1</em><em>. </em><em>week</em><em> </em><em>eyesight</em>

<em>2</em><em>. </em><em> </em><em>weak</em><em> </em><em>brain</em><em> </em><em>power</em>

<em>3</em><em>. </em><em>loss</em><em> </em><em>of</em><em> </em><em>concentra</em><em>tion</em><em>.</em><em>.</em><em>.</em>

<em>hope</em><em> </em><em>it</em><em> </em><em>helps</em><em> </em><em>u</em>

4 0
3 years ago
Characteristics of a deterministic system<br>​
Fiesta28 [93]

Explanation:

deterministic system is a involved in development of future states of the system is called deterministic determinstic system.

3 0
3 years ago
9.5 Code Practice edhesive
Ann [662]

Answer:

a = [[34,38,50,44,39],

    [42,36,40,43,44],

    [24,31,46,40,45],

    [43,47,35,31,26],

    [37,28,20,36,50]]

   

sum=0

for r in range(len(a)):

   for c in range(len(a[r])):

       sum = sum + a[r][c]

       

       

print("Sum of all values: " + str(sum) + "\n\n")

print("Average of all values: " + str(sum / (len(a) * len(a))))

Explanation:

I got 100%.

3 0
3 years ago
Read 2 more answers
12. The best method of protecting the residential user with an Internet connection from intruders out on the Internet is to use
Lyrx [107]

Answer:

Updated OS software patches

Explanation:

Firstly we need to know that patches are those software updates as well as operating system updates that addresses the vulnerabilities In a program or a products security. Software operators may decide to roll out new updates which have the power to fix performance bugs in a program as well as providing more enhanced methods of security.

3 0
3 years ago
Other questions:
  • Are there protections for people in terms of what data can be collected by different sites?
    10·1 answer
  • Technology not only influences what formats are possible in media, it also defines their contents.
    13·1 answer
  • PLEASE HELP!!! History abounds with instances in which the work of scientists and artists were affected by the political, religi
    9·1 answer
  • A Windows user right-clicks on his desktop. What is he planning to do?
    10·1 answer
  • The Hydrosphere contains (4 points)
    10·1 answer
  • What determines the number of times that a condition-controlled loop will repeat?
    9·2 answers
  • Can anyone please help?
    13·1 answer
  • Describe an example of a very poorly implemented database that you've encountered (or read about) that illustrates the potential
    12·1 answer
  • An articulated robot has a T-type wrist axis that can be rotated a total of 2 rotations (each rotation is a full 3600 ). It is d
    15·1 answer
  • The letters G, H, T, Y, B, and N are what type of keys?
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!