Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

Question about java for lab class for compiler errors and editing a class

Notice that there are compiler errors in part5.Lab5. You will notice that the code in methods check_1, check_2, check_3, and check_4 makes calls to methods that should be defined in Vocabulary. This gives you a hint of something that you need to add to the Vocabulary class.

Keep in mind that you may edit ONLY the Vocabulary class, as that's the only class from part 5 that will be submitted. The Vocabulary class must make use of the part5.Words class.

----------The Lab5.java code is:-------------------------

package part5;

public class Lab5 {

private Vocabulary _vocab;

public Lab5() {
    _vocab = new Vocabulary();
    check_01();
    check_02();
    check_03();
    check_04();
    check_05();
    check_06();
    check_07();
    check_08();
    check_21();
    check_22();
    check_23();
    check_24();
}

public void check_01() {
    System.out.println("I expected to get:");
    System.out.println("    a");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1());
}

public void check_02() {
    System.out.println("I expected to get:");
    System.out.println("    some");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1());
}

public void check_03() {
    System.out.println("I expected to get:");
    System.out.println("    every");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1());
}

public void check_04() {
    System.out.println("I expected to get:");
    System.out.println("    a");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1());
    _vocab.get1();
    _vocab.get1();
}

public void check_05() {
    System.out.println("I expected to get:");
    System.out.println("    cat");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get2());
}

public void check_06() {
    System.out.println("I expected to get:");
    System.out.println("    dog");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get2());
}

public void check_07() {
    System.out.println("I expected to get:");
    System.out.println("    rat");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get2());
}

public void check_08() {
    System.out.println("I expected to get:");
    System.out.println("    cat");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get2());
    _vocab.get2();
    _vocab.get2();
}

// When submitting to Web-CAT additional test cases, 09 through 20, will be run.

public void check_21() {
    System.out.println("I expected to get:");
    System.out.println("    a cat chased some dog");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1() + " " + _vocab.get2() + " " + _vocab.get3() + " " + _vocab.get4() + " " + _vocab.get5());
}

public void check_22() {
    System.out.println("I expected to get:");
    System.out.println("    some dog scared every rat");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1() + " " + _vocab.get2() + " " + _vocab.get3() + " " + _vocab.get4() + " " + _vocab.get5());
}

public void check_23() {
    System.out.println("I expected to get:");
    System.out.println("    every rat convinced a cat");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1() + " " + _vocab.get2() + " " + _vocab.get3() + " " + _vocab.get4() + " " + _vocab.get5());
}

public void check_24() {
    System.out.println("I expected to get:");
    System.out.println("    a cat chased some dog");
    System.out.println("What I got was: ");
    System.out.println("    " + _vocab.get1() + " " + _vocab.get2() + " " + _vocab.get3() + " " + _vocab.get4() + " " + _vocab.get5());
}

}

-------The Vocalbulary.java is:-------------

package part5;

public class Vocabulary {

public Vocabulary() {
}

}

---------The Words.java is:---------------------

package part5;

public class Words { private String _word1; private String _word2; private String _word3;

public Words(String s1, String s2, String s3) {
    _word1 = s1;
    _word2 = s2;
    _word3 = s3;
}

public String getWord() {
    String answer = _word1;
    rotate();
    return answer;
}

private void rotate() {
    String temp = _word1;
    _word1 = _word2;
    _word2 = _word3;
    _word3 = temp;
}

}