Home / Expert Answers / Computer Science / please-help-fix-my-code-nbsp-this-is-the-question-and-code-given-the-intnode-class-define-the-fin-pa543

(Solved): Please help fix my code.  This is the question and code Given the IntNode class, define the fin ...



Please help fix my code. 

This is the question and code

Given the IntNode class, define the findMax() method in the CustomLinkedList class that returns the largest value in the list or returns -99 if the list is empty. Assume all values in the list are non-negative.

Ex: If the list contains:

head -> 14 -> 191 -> 186 -> 181

findMax(headObj) returns 191.

Ex: If the list contains:

head -> 

findMax(headObj) returns -99.

 

CustomLinkedList.java

public class CustomLinkedList {
   
   public static int findMax(IntNode headObj) {
      IntNode temp = headObj;
      int ans = -99;
   
      while(temp.getNext() != null){
          if(temp.getNodeData() > ans){
              ans = temp.getNodeData();
          }
          temp = temp.getNext();
      }
      
      // return the ans.
      return ans;
   }
   
   public static void main(String[] args) {
      IntNode headObj; 
      IntNode currObj;
      IntNode lastObj;
      int i; 
      boolean result;
      
      // Create head node
      headObj = new IntNode(-1); 
      lastObj = headObj;
      
      // Add nodes to the list
      for (i = 0; i < 20; ++i) { 
         currObj = new IntNode(i);         
         lastObj.insertAfter(currObj); 
         lastObj = currObj;
      }    
      
      max = findMax(headObj);
      System.out.println(max);
   }
}

 

 

I have two errors which are: CustomLinkedList.java:36: error: cannot find symbol
findMax (headObj);
max =
symbol: variable max
location: class CustomLinke

CustomLinkedList.java:36: error: cannot find symbol findMax (headObj); max = symbol: variable max location: class CustomLinkedList CustomLinkedList.java:37: error: cannot find symbol System.out.println (max); symbol: variable max location: class CustomLinkedList 2 errors


We have an Answer from Expert

View Expert Answer

Expert Answer


input code: output: codE: public class CustomLinkedList{ /*make method for find max*/ public static int findMax(IntNode headObj) { IntNode temp = headObj; /*declare v
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe