Skip to the content.

Classes

AP CSA

public class Cat {
    private String sound;

    public Cat(String noise) {
        this.sound = noise;
    }

    public static String reverse(String str) {
        char[] chars = str.toCharArray();
        int left = 0;
        int right = chars.length - 1;

        while (left < right) {
            char temp = chars[left];
            chars[left] = chars[right];
            chars[right] = temp;
            left++;
            right--;
        }

        return new String(chars);
    }

    public String makeQuiteNoise() {
        if (this.sound == null || this.sound.isEmpty()) {
            return null;
        } else {
            String lowercaseStr = this.sound.toLowerCase();
            return lowercaseStr;
        }
    }

    public String makeReverseNoise() {
        if (this.sound == null || this.sound.isEmpty()) {
            return null;
        } else {
            String reversed = reverse(sound);
            return reversed;
        }
    }
}


HW Section


public interface StudyPractice {
    String getProblem();

    void nextProblem();
}

public class MultProblems implements StudyPractice {
    private int first;
    private int second;

    public MultProblems(int first, int second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public String getProblem() {
        return first + " times " + second;
    }

    @Override
    public void nextProblem() {
        this.second = second + 1;
    }


}

StudyPractice p1 = new MultProblems(7, 3);
System.out.println(p1.getProblem());
p1.nextProblem();
System.out.println(p1.getProblem());
7 times 3
7 times 4