Classes FRQ
public class Cat {
// instance variable sound
private String sound;
/**
* constructor with noise input for sound
*
* @param noise sound
*/
public Cat(String noise) {
sound = noise;
}
/**
* returns sound in all lowercase
*
* @return lowercase sound
*/
public String makeQuietNoise() {
return sound.toLowerCase(); // using toLowerCase() to convert String to lowercase
}
/**
* returns sound in reverse
*
* @return reverse sound
*/
public String makeReverseNoise() {
return new StringBuilder(sound).reverse().toString(); // using StringBuilder class to reverse the String, then covert it back to String with toString()
}
}
public interface StudyPractice {
/**
* returns the current practice problem
*/
String getProblem();
/**
* changes to the next practice problem
*/
void nextProblem();
}
public class MultPractice implements StudyPractice {
// instance variables for the two integers c1 and c2
private int c1, c2;
/**
* constructor that initializes c1 and c2
*
* @param c1 first integer
* @param c2 second integer
*/
public MultPractice(int c1, int c2) {
this.c1 = c1;
this.c2 = c2;
}
/**
* prints out the problem, similar to a toString function
*
* @return c1 TIMES c2
*/
public String getProblem() {
return c1 + " TIMES " + c2; // String concatenation
}
/**
* updates to the next problem
*/
public void nextProblem() {
c2++; // adds one to c2 to produce next problem
}
}