Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to fix my code so it fits the unit test?

843789Jul 28 2010 — edited Jul 28 2010
sorry i'm new to this forum and first time posting so bare with me for the long post for just a simple question.

i've been asked to write a piece of array code that gets 5 numbers from user and then display the highest number inputted.
here is my code:
public class Math2
{
    private int[] Math2;

    public Math2()
    {

    }
    
    public int getHighest(int[] Math2)
    {
        java.util.Arrays.sort(Math2);
        int largest = Math2[Math2.length-1];
        return largest;
    }
}
now my code works fine but here comes the problem... i've been given a unit test to test my code, and whats happening is that they dont mix lol, i've been getting error and i have no idea how to get this fixed

unit test code is this:
public void testHighestFirst()
    {
        Math2 math1 = new Math2(new int[]{5, 1, 2, 4, 3});
        assertEquals(5, math1.getHighest());
    }
the error i'm getting is this:

"cannot find symbol - constructor Math2(int[])"

what can i do to get this fixed? ( i use blue J if thats even relevant at all)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 25 2010
Added on Jul 28 2010
13 comments
153 views