Answer:
Following are the code to the given points:
Explanation:
For point 8.1:
public String max()//defining a method max
{
String maxVal=null;//defining a string variable that holds a value
for(int x=0;x<n;x++)
{
if(maxVal==null || a[i].compareTo(maxVal)>0)//defining if blok to comare the value
{
maxVal=a[i];//holding value in maxVal variable
}
}
return maxVal;//return maxVal variable value
}
For point 8.2:
public void push(String item)//defining a method push that accepts item value in a parameter
{
a[n]=item;//defining an array to hold item value
if(n==0 || item.compareTo(maxVals[n-1])>0)//use if to comare item value
{
maxVals[n]=item;//holding item value in maxVals variable
}
else
{
maxVals[n]=maxVals[n-1];//decreasing the maxVals value
}
n++;//incrementing n value
}
public String pop()//defining a method pop
{
return a[--n];//use return value
}
public String max()//defining a method max
{
return maxVals[n-1];//return max value
}
- In the first point, the max method is declared that compares the string and returns its max value.
- In the second point, the push, pop, and max method are declared that works with their respective names like insert, remove and find max and after that, they return its value.