// https://piazza.com/class#fall2012/cs46a/911
Part A. In the Word
class of Homework 8C, reimplement the
methods
public void printLeftTriangle()
public void printRightTriangle()
public void printShifts()
so that you do not use substring
. Instead, use
the charAt
method and two nested loops per method.
Draft: Implement the printLeftTriangle
method in this way.
Part B. In the Word
class of Lab 8, add methods
public boolean allLettersAreTheSame()
Returns true
if all letters of this word are the same.
public boolean allLettersAreDifferent()
Returns true
if all letters of this word are different.
public String mostFrequentLetter()
Returns a string containing the letter that occurs most frequently. If there are multiple such substrings, returns the leftmost one. If there is none, return null.
For all three methods, you may assume that the word contains at least two
letters. You can use substring
in this part.
Draft: Just implement allLettersAreTheSame
.
Part C. In the Word
class of Lab 8, add methods
public void printSubstrings(int length)
Prints all substrings of the given length, from left to right. You can assume that length > 0.
public String longestRepeatedSubstring()
Returns the longest substring of the word that repeats elsewhere in the word (outside the substring). If there are multiple such substrings, returns the leftmost one.
public int distinctSubstrings()
Returns the number of distinct nonempty substrings of the word.
Call your class Word3
.
Draft: printSubstrings