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

  Java application which creates bank records

Write down a java application which creates 10000 bank records and the allow user ti enter a balance and customer account info. using a an account number.

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

  Write java application to show successive element of array

Write down java application named GoTooFar which declares the array of 5 integers and stored five values in array. write try block in which you loop to show each successive element of array.

  Communication with an smtp server

Develop a graphical user interface based java program that can communicate with a real SMTP email server for sending emails

  Create a project in eclipse

Create a new project

  Design a course registration system

Create an application which represents a simplified course registration system using ArrayLists and HashMaps.

  Create java applet to represent grade of gas

Write a java applet (not a java application program) for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use.

  Instance methods

instance methods: setWidth(double w), setHeight(double h), double getWidth(), double getHeight() and double getArea() * A triangle's area is calculated by width*height*0.5  * all variables are private and methods public.

  Create a recursive factorial program

Assignment 1: 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 !. For example, if the input is 4, the output could be:

  Creates an array named odds

Write code that creates an array named odds and stores all odd numbers between -6 and 38 into it using a loop. Make the array's size exactly large enough to store the numbers.

  Fixing errors in a java program

You coded the following on line ten of the class MyApplet.java:

  Develop java applet that will help elementary school student

Develop a Java applet that will help an elementary school student learn multiplication. Use the Math.random method or a Random object to produce two positive one-digit integers.

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