Question: Design and trace FunWithStack algorithms public class FunWithStack { public void decimalToBinary() { System.out.println(DECIMAL TO BINARY CONVERTER); // TODO PROJECT #1 Scanner keyboard = new

  • Design and trace FunWithStack algorithms
public class FunWithStack { public void decimalToBinary() { System.out.println("DECIMAL TO BINARY CONVERTER"); // TODO PROJECT #1 Scanner keyboard = new Scanner(System.in); Stack stack = new Stack<>(); try { do { System.out.println(" Please enter a positive integer, or type \"stop\""); int decimalNumber = keyboard.nextInt(); System.out.print(decimalNumber + " in binary is --> "); // YOUR CODE GOES HERE System.out.println(); } while (true); } catch (InputMismatchException ime) { System.out.println("Done with conversion. "); } } public void ancientMultiplier() { // TODO PROJECT #1 // http://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication Stack op1 = new Stack<>(); Stack op2 = new Stack<>(); } public ArrayList noAdjacentDuplicates(int... input) { // TODO PROJECT #1 ArrayList result = new ArrayList<>(); Stack stack = new Stack<>(); System.out.println("input = " + Arrays.toString(input)); return result; } public static void main(String[] args) { FunWithStack funWithStack = new FunWithStack(); System.out.println("*** DECIMAL TO BINARY CONVERTER ***"); funWithStack.decimalToBinary(); System.out.println("*** ANCIENT MULTIPLIER ***"); funWithStack.ancientMultiplier(); System.out.println("*** ELIMINATING ADJACENT DUPLICATES ***"); System.out.println("--> testcase #1"); ArrayList result = funWithStack.noAdjacentDuplicates(1, 5, 6, 8, 8, 8, 0, 1, 1, 0, 6, 5); ArrayList expected = new ArrayList<>(); expected.add(1); if (result.equals(expected)) System.out.println("result = " + result + " CORRECT"); else { System.out.println("INCORRECT, expected: " + expected); System.out.println("got: " + result); } System.out.println(" ---> testcase #2"); result = funWithStack.noAdjacentDuplicates(1, 9, 6, 8, 8, 8, 0, 1, 1, 0, 6, 5); expected.clear(); expected.add(1); expected.add(9); expected.add(5); if (result.equals(expected)) System.out.println("result = " + result + " CORRECT"); else { System.out.println("INCORRECT, expected: " + expected); System.out.println("got: " + result); } System.out.println(" ---> testcase #3"); result = funWithStack.noAdjacentDuplicates(1, 1, 6, 8, 8, 8, 0, 1, 1, 0, 6, 5); expected.clear(); expected.add(5); if (result.equals(expected)) System.out.println("result = " + result + " CORRECT"); else { System.out.println("INCORRECT, expected: " + expected); System.out.println("got: " + result); } System.out.println(" ---> testcase #4"); result = funWithStack.noAdjacentDuplicates(1, 1, 1, 5, 6, 8, 8, 8, 0, 1, 1, 0, 6, 5); expected.clear(); if (result.equals(expected)) System.out.println("result = " + result + " CORRECT"); else { System.out.println("INCORRECT, expected: " + expected); System.out.println("got: " + result); } System.out.println("Done!"); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!