Question
Java -- Please carefully !! * You may not add any methods to the node class. * You may not use the toString method to
Java -- Please carefully !! * You may not add any methods to the node class. * You may not use the toString method to solve any of the toDos * You may NOT use arrays or other Java classes!
~ This would be for testing purposes ~
public String toString () { StringBuilder result = new StringBuilder (""); for (Node x = first; x != null; x = x.next) result.append ( x.item); return result.toString (); } public static Program of(String s) { Node first = null;
for (int i=s.length()-1; i >=0; i--) first = new Node (s.charAt(i), first);
Program result = new Program (); result.first = first; return result; }
private static void testmaxCharacter (char expected, String sList) { Program list = Program.of (sList); String sStart = list.toString (); char actual = list.maxCharacter(); boolean status = true; if (expected != actual) { StdOut.format ("Failed [\"%s\"].maxCharacter(): Expecting: %c Actual: %c ", sStart, expected, actual); status = false; } String sEnd = list.toString (); if (! sStart.equals (sEnd)) { StdOut.format ("Failed [\"%s\"].maxCharacter(): List changed to %s ", sStart, sEnd); status = false; } if ( status && showMeSuccess) StdOut.format ("Success maxCharacter(): Result: %c input: %s ", actual, sStart); }
Use this format to test:
testmaxCharacter ('a', "a"); testmaxCharacter ('d', "abcdc"); testmaxCharacter ('z', "zzyymmb"); testmaxCharacter ('z', "eezzg"); StdOut.println("*** end maxCharacter Tests ");
* * maxCharacter * * a function to compute the 'maximum' character in the list using recursion * You will want to create a helper function to * do the recursion * * precondition: list is not empty * * Examples: * ("ababcdefb"].maxCharacter() == 'f' * ["eezza") .maxCharacter() == 'z' * ["a"] .maxCharacter() == 'a' */ public char maxCharacter (){ return '*'; //TODO 1: fix thisStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started