Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A TotemPole is compromised of different animial heads (Bear, Snake, and Eagle).

ID: 662558 • Letter: A

Question

A TotemPole is compromised of different animial heads (Bear, Snake, and Eagle).  Eagles can only be at the top of the pole. Each animal head adds a different amount of power to the TotemPole.  Bears are the most sacred to the Gashunongan people and add 5 power points to the TotemPole.  Snakes add 3 power points.  Eagles add 2 power points. Since Bears are the most sacred, a Gashunongan Chief's TotemPole must have at least 3 Bears in a row at some place in the TotemPole.



1)Develop an interface called TotemPole.  A TotemPole has the following methods:
         int power(); // the total power of the pole
         int height(); // the number of heads in the pole
         boolean chiefPole(int bearCount); // is this pole worthy of a chief?
                 // bearCount is how many bears encountered in a row so far


2) Develop the class Bear that implements the TotemPole interface.  Bears have the following constructor:
         public Bear(TotemPole rest);

3) Develop the class Snake that implements the TotemPole interface.  Snakes have the following constructor:
         public Snake(TotemPole rest);

4) Develop the class Eagle that implements the TotemPole interface.  Eagles have the following constructor:
         public Eagle();


This is the tester/main program
http://users.csc.calpoly.edu/~jworkman/102/Lab10/TotemTest.java

Explanation / Answer

public class TotemTest { TotemPole p1, p2, p3; public static void main(String[] args) { new TotemTest().run(); } public TotemTest() { p1 = new Bear( new Bear( new Snake( new Snake( new Snake( new Bear( new Eagle())))))); p2 = new Snake( new Bear( new Bear( new Bear( new Snake( new Eagle()))))); p3 = new Eagle(); } public void run() { boolean pass = true; pass &= testHeight(); pass &= testPower(); pass &= testChiefPole(); if (pass) System.out.println("Congrats, you pass. The Gashunongan people rejoice!"); else System.out.println("Not done yet. I hope the Gashunongan people aren't head hunters!"); } public boolean testHeight() { boolean pass = true; pass &= test(p1.height(), 7, 1); pass &= test(p2.height(), 6, 2); pass &= test(p3.height(), 1, 3); return pass; } public boolean testPower() { boolean pass = true; pass &= test(p1.power(), 26, 4); pass &= test(p2.power(), 23, 5); pass &= test(p3.power(), 2, 6); return pass; } public boolean testChiefPole() { boolean pass = true; pass &= test(p1.chiefPole(0), false, 7); pass &= test(p2.chiefPole(0), true, 8); pass &= test(p3.chiefPole(0), false, 9); return pass; } private static boolean test(int test, int expect, int testNum) { if (test != expect) { System.out.println(" FAILED test #" + testNum); return false; } return true; } private static boolean test(boolean test, boolean expect, int testNum) { if (test != expect) { System.out.println(" FAILED test #" + testNum); return false; } return true; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote