Your letterinventory class must use an array

Assignment Help JAVA Programming
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();
}
}

Reference no: EM13161739

Questions Cloud

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 ..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Record managing system application

Build a student record managing system application

  World data app

Prepare WorldDataApp project. It implements the NameIndex portion, including creating it in SetupProgram, and searching, viewing and updating it in UserApp program.

  Write java application to input three integers from user

Write Java application that inputs three integers from user and displays sum, average, product, smallest, and largest of the numbers.

  Huge integer class

Huge Integer Class) Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods parse, toString, add and subtract. Method parse should receive a String, extract each digit using met..

  Write servlet code for accepting two numbers from user

Write the servlet code for accepting two numbers from user show addition and multiplication of numbers. If error occurs, then call JSP error page to display suitable error message.

  Write java program using array list object

Write a java program (using eclipse) using ArrayList object to allow the professor to enter student's name, his or her's four test scores.

  Build the gui layout of the game

Build the Build the GUI layout of the game in java.

  Develop a gui based java program

Designing and developing a College Registration program

  Write program in java-calculate and display mortgage payment

Write the program in Java (with a graphical user interface) and have it calculate and display the mortgage payment amount from user input of the amount of the mortgage.

  Implement the lexical and syntactic analysis

Implement the lexical and syntactic analysis of Minifun programming language.

  Java program to find a value at in index

Construct a main class named Array Program that generates an array of 50-integers, all ranging from one to one hundred.

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd