Skip to content

chrisg220/LetterCounter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Letter Counter

This program uses arrays that can be used to keep track of an inventory of letters of the alphabet. The constructor for the class takes a String and computes how many of each letter are in the String. This is the information the object keeps track of (number of a’s, b’, etc). It ignores the case of the letters and ignores anything that is not an alphabetic character (e.g., it ignores punctuation characters, digits and anything else that is not a letter). Your class should have the following public methods.

Public Methods

constructs a LetterInventory object with an inventory of each letter passed in.

LetterCounter(String data)

pre : char is a letter (throws IllegalArgumentException if not) post: returns the count for the given letter

int get(char letter)

pre : char is a letter && value >= 0 (throws IllegalArgumentException if not) post: sets the count for given letter to given value

void set(char letter, int value)

post: returns the current sum of letter counts in the LetterInventory instance

int size()

post: returns true if array is empty, false otherwise

boolean isEmpty()

post: returns a sorted lowercase String of the inventory surrounded with square brackets

String toString()

pre : other argument must be a LetterCounter reference post: returns a new LetterCounter object that represents the sum of this LetterCounter and the other given LetterCounter.

LetterInventory add(LetterInventory other)

pre : other argument must be a LetterCounter reference post: returns a new LetterInventory object that represents the difference between the other LetterCounter from this LetterCounter.

LetterInventory subtract(LetterInventory other)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages