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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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