Reference no: EM13161739
John A.
Implement two classes and use an array of objects to count the number of times each letter occurs in a text file.
Counter - each counter should maintain a single count (don't allocate an array here)
Counter() - constructor that initializes the count to 0
void incrementCount() - increases the count by 1
void resetCount() - sets the count to 0
String toString() - returns a String representation of the count (e.g., "13")
boolean equals(Counter c) - returns true if both Counters store the same count
You will use the Counter class in a separate class called LetterInventory, which has the following methods:
LetterInventory - stores the count for all 26 letters
LetterInventory() - constructs the inventory (an array of 26 Counter objects)
void countOccurrences(Scanner file) - counts the frequency of each letter in a file
void displayTable() - displays the frequencies of each letter in the inventory
void resetInventory() - resets all of the counts to 0
Your LetterInventory class must use an array of Counter objects. Note that there is no nextChar method in the Scanner class. You must use the next() method and then use a loop through the characters of the token that is returned. Ignore any character that is not a letter. You should also treat 'a' and 'A' as the same letter.
To convert a letter into an integer index, subtract 'a' or 'A' from it. The expression (letter - 'a') will yield an integer between 0 and 25 for any lowercase letter. Should output:
a: xx
b: xx
c: xx
d: xx
ect..
Drive Code:
import java.util.Scanner;
import java.io.File;
public class LetterCounter {
public final static String filename = "testFile.txt";
// Driver to test LetterInventory class
public static void main(String[] args) {
Scanner inputFile = null;
try {
inputFile = new Scanner(new File(filename));
} catch (Exception e) {
System.out.println("File could not be opened: " + filename);
System.exit(0);
}
LetterInventory inventory = new LetterInventory();
inventory.countOccurrences(inputFile);
inventory.displayTable();
inventory.resetInventory();
}
}
The hr department has sensitive information
: The HR department has sensitive information that can only be viewed by members of the HR department and executive offices. Each location has computers and printers for use within the individual departments but that not to be used by employees from an..
|
Write a program that reads in a list of numbers from a file
: write a program that reads in a list of numbers from a file and adds up all those numbers. You may hard code in the name of the file, allowing the user to input the filename is not required
|
What is the average response time for this system?
: A web server receives a request every 50ms and processes web requests every 8 ms. Using queuing theory, 1. What is the average response time for this system?
|
Java''s type int has limit onhow large aninteger it can store
: Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an integer as an array of digits. Write an interactive program that adds two integers of up to 50 digits each.
|
Your letterinventory class must use an array
: Your LetterInventory class must use an array of Counter objects. Note that there is no nextChar method in the Scanner class. You must use the next() method and then use a loop through the characters of the token that is returned. Ignore any character..
|
Pointer variables to demonstrate shallow and deep copy
: Using C++, write a program that uses pointer variables to demonstrate shallow and deep copy. The program should give the user the choice to do the following:
|
Write method called median that accepts an array of integer
: Write a method called median that accepts an array of integers as its parameter and returns the median of the numbers in the array.
|
If interest is compounded annually
: If interest is compounded annually, it grows as follows. Suppose P0 is the initial amount and INT is the interest rate per year. If P1 and P2 represent the balance at the end of the first and second year
|
Demonstrate the construction and output of an array
: In fluid mechanics, the Reynolds number (Re) is a dimensionless quantity that is used to help predict similar flow patterns in different fluid flow situations. For example, Reynolds numbers can be computed for different velocities of fluid flow over ..
|