I seem to be stuck on what seems to be a pretty basic assignment. I was wondering if anyone could possibly lead me to the right direction and explain to me what is wrong. I have created an array with premade values inserted. Now I have to get the min/max values of this array and display them as well. I keep getting these two errors
".java:126: error: method getMax in class HighArray cannot be applied to given types;"
".java:126: error: method getMin in class HighArray cannot be applied to given types;"
If anyone could possibly help me out and explain why this is, it would be greatly appreciated. Thank you!
class HighArray
{
private long[] a;
private int nElems;
public HighArray(int max)
{
a = new long[max];
nElems = 0;
}
//Search Method
public boolean find(long searchKey)
{
int j;
for(j=0; j<nElems; j++)
if(a[j] == searchKey)
break;
if(j == nElems)
return false;
else
return true;
}
//Insert method
public void insert(long value)
{
a[nElems] = value;
nElems++;
}
//Delete method
public boolean delete(long value)
{
int j;
for(j=0; j<nElems; j++)
if( value == a[j] )
break;
if(j==nElems)
return false;
else
{
for(int k=j; k<nElems; k++)
a[k] = a[k+1];
nElems--;
return true;
}
}
//Display Array Contents
public void display()
{
for(int j=0; j<nElems; j++)
System.out.print(a[j] + " ");
System.out.println(" ");
}
//Max Method
public static int getMax(int[] a)
{
int maxValue = a[0];
for(int i=1;i < a.length;i++)
{
if(a[i] > maxValue)
{
maxValue = a[i];
System.out.print("The max value is" + a[i]);
}
}
return maxValue;
}
//Min Method
public static int getMin(int[] a)
{
int minValue = a[0];
for(int i=1;i<a.length;i++)
{
if(a[i] < minValue)
{
minValue = a[i];
System.out.print("The min value is" + a[i]);
}
}
return minValue;
}
}
public class Assignment
{
public static void main(String[] args)
{
int maxSize = 100;
HighArray arr = new HighArray(maxSize);
arr.insert(77);
arr.insert(99);
arr.insert(44);
arr.insert(55);
arr.insert(-22);
arr.insert(88);
arr.insert(-11);
arr.insert(00);
arr.insert(66);
arr.insert(-33);
arr.display();
arr.getMax();
arr.getMin();
int searchKey = 35;
if( arr.find(searchKey) )
System.out.println("Found" + searchKey);
else
System.out.println("Can't Find " + searchKey);
arr.delete(00);
arr.delete(55);
arr.delete(99);
arr.display();
}
}
See Question&Answers more detail:os