-2

So im writing a method for my computer science class in which im trying to make a kinda like walking path thing. What i want to do is test the methods where the isLevelSegment part will return true if the difference between the maximum and minimum elevation in the walking path segment is less than or equal to ten meters and the isDifficult method is trying to see if there are 3 or more elevation changes in a path ( elevation changes are at least 30 meters up or down ). All my code is written [ idk if its correct or not, i think it is ] and basically and idk why im having a really hard time writing the main method to test it. Help?

public class Lab11 {

public class WalkingPath
{
    private int[] markers;

public boolean isLevelSegment (int start, int end )
{
int min = 1;
int max = 0;


for (int i = start; i<= end ; i ++)
{
    if (markers[i] > max)
        max = markers[i];
    if (markers[i] < min || min == -1)
        min = markers [i];
}
if ((max - min) <= 10)
return true;
else 
    return false;

}





public boolean isDifficult ()
 {
     int changes = 0; 
        for ( int i = 1 ; i< markers.length ; i ++)
        {
            if ((markers[i] - markers [i - 1]) >= 30)
                changes ++;
        }
        if (changes >= 3)
            return true;
        else 
            return false;
 }
    }

}

1 Answers1

0

Well, you need a constructor for your class, for one. Also, you need a main method in one of your classes which the compiler (the computer) will start at. So, if you have a single class like the one you posted, add a constructor and a main method. In that main method, instantiate a new instance of your class and in the constructor start the task you're trying to accomplish.

If any of those terms are confusing, google them. They're all standard and should be easily findable.

Araymer
  • 1,315
  • 1
  • 10
  • 16