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
Where is the spell checker found in excel?
fenix001 [56]
Except keyboard of F7 and Spell Checkbutton in toolbar, you are also able to apply Spelling check command fromExcel 2007/2010/2013/2016 Ribbon: Click the Review tab; Go to Proofing group; Then you will view the Spellingbutton , that's Spell Check command.



hope this helps
5 0
4 years ago
Read 2 more answers
The average lease payment for a new vehicle is just over $450 per month for a three-year...
hichkok12 [17]

Answer:

it depends on your insurance company

Explanation:

7 0
3 years ago
Write a SELECT statement that returns these columns from the Products table: The list_price column The discount_percent column A
Anarel [89]

Answer:

Check the explanation

Explanation:

The SELECT statement that returns these columns are:

SELECT

   list_price,

   discount_percent,

   ROUND (list_price * discount_percent / 100,2)  AS discount_amount

FROM

   products;

----------------------------------------------------------------------

6 0
3 years ago
Please!! I need help, this is due by tonight!!!
lyudmila [28]

Answer:

sorry if it is too late but I think it is d

Explanation:

4 0
3 years ago
An application that allows you to connect to the millions of networks on the Internet is referred to as a(n) _____. Internet bro
storchak [24]
It's called an Internet Browser. Examples include Chrome, Firefox, and Internet Explorer.
4 0
3 years ago
Other questions:
  • Step into the year 2028. How are people viewing digital video? Or have we moved on to a completely new format?
    13·1 answer
  • Write a function analyze_text that receives a string as input. Your function should count the number of alphabetic characters (a
    5·1 answer
  • What does N represent when analyzing algorithms?
    15·1 answer
  • Live.com is Microsoft's free web-based email provider.<br> A. True<br> B. False
    6·1 answer
  • The program processes the command line arguments. The arguments indicate which signals to catch:________. A. The program emits a
    10·1 answer
  • I need help plzzzzzzzz
    10·2 answers
  • The most widely used computer device​
    6·2 answers
  • rue or false: The first web browser was introduced to the public in the 1970s and started the explosive growth of the Internet i
    15·1 answer
  • Q.3.1 Explain why devices on a network need addresses. (5)​
    10·1 answer
  • write a program that keeps names and email addresses in a dictionary as key-value pairs. the program should display a menu that
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!