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
Ted is looking for a reliable source for his paper. Which of the following sites would be considered reliable?
Lubov Fominskaja [6]

Answer:

A site where the author's information and qualifications are listed

Explanation:

When conducting online research, it is recommended that you look for reliable sources that will provide concrete evidence based on credible results. Credibility, in most cases, will start with the authors of the articles. Look for articles written by renown and respected authors. Evaluate keenly and avoid Wikipedia authors who are mostly anonymous. Determine their expertise, and if you can, do an additional Google research on them and find out whether they are credible or not.

8 0
3 years ago
12. In Microsoft Word, when you highlight existing text you want to replace, you are in A. basic mode. B. automatic mode. C. ins
Tresset [83]
I know you're in the formatting toolbar, but I am uncertain of what mode that would be in. 

From searching over the web I see a lot about overtype/insert mode, so I am leaning towards C, but I don't want to get the question wrong for you. 
8 0
3 years ago
Read 2 more answers
How do professionals address their problems?
8090 [49]

Answer:

b, with grace and maturity

6 0
3 years ago
Read 2 more answers
To hide gridline when you display or print a worksheet
Bingel [31]
Hide it under the copier
7 0
4 years ago
If Number = 7, what will be displayed after code corresponding to the following pseudocode is run? (In the answer options, new l
kherson [118]

Answer:

5,10; 6,12; 7,14

Explanation:

We will demonstrate the iteration of the loop:

First iteration: Number = 7, Count = 5 at the beginning. We will check if Count <= Number? Since it is correct, prints 5,10. Increment the Count by 1.

Second iteration: Number = 7, Count = 6. We will check if Count <= Number? Since it is correct, prints 6,12. Increment the Count by 1.

Third iteration: Number = 7, Count = 7. We will check if Count <= Number? Since it is correct, prints 7,14. Increment the Count by 1.

Forth iteration: Number = 7, Count = 8. We will check if Count <= Number? Since it is not correct, the loop stops.

8 0
3 years ago
Other questions:
  • Describe the "Mister Splashy Pants" campaign. How did it start? What happened?
    7·2 answers
  • Keep getting the message i failed to sign in to email on my phone but i can open my email. whats going on?
    10·2 answers
  • What is the purpose of system calls, and how do system calls relate to the OS and to the concept of dual-mode (kernel-mode and u
    14·1 answer
  • Although heart rate increases and decrease depending upon activity level on average a typical person heart rate is about _____ b
    10·1 answer
  • Can you call a mobile a computer. It Yes<br>why? If No why​
    7·2 answers
  • You want to write a Python program to compute the average of three integer quiz grades for a single student. Decide what variabl
    8·1 answer
  • Many company websites are now designed to do more than just sell a product. These​ websites, known as​ __________ websites, atte
    14·1 answer
  • Who like the videos where is clown is from :)
    6·1 answer
  • 3.4 lesson practice quiz edhesive
    11·1 answer
  • Can someone answer this for me will award brainliest lol
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!