Calling Methods In Java

Man of Honour
Joined
15 Mar 2004
Posts
28,140
Location
Liverpool
Hi, I was wondering how to call certain methods in Java?

I have a class file which contains different methods, and I'm supposed to create a main.java file such that the results of these is called and I can then display it. I'm not sure how to do this though.

One of the methods is:

Code:
static int[ ] Method1(int[ ] L, int n)

and to call it we've been told that:

Given a n-element array, L, whose value are distinct integers, the statement
Code:
P = Sorting.Method1(L,n);
will return an n + 1 element integer array in
which {P[1], P[2], . . . , P[n]} hold all of the elements in L sorted into ascending order, i.e. for each element L some position j in P will have P[j] = L; furthermore for each k with 1 ≤ k < n, the value P[k] will be less than the value P[k + 1].

Any help recieved will be gratefully receieved. Quite stuck on this :(

Edit - letters have been changed because otherwise it's confusing..
 
Last edited:
Grrr, god damnit, I've done the bulk of the programming - but it's giving me two errors that I for the life of me can't figure out. Can anybody help I'm going potty over it.

Code:
import java.util.*;
import java.util.Random;

public class Main {
    
private int [] PermTwo;
private Random RandomSequence;
private int size = 100;              
private int counter2;
private int[] SortA, SortB, SortC, SortD;
private int[] Permutation;


public Main() {
    
Permutation = new int[size];        

SortA = new int[size+1];
SortB = new int[size+1];
SortC = new int[size+1];
SortD = new int[size+1];

RandomSequence = new Random();
}

	public void MethodOne()	{
	SortA = new int[size+1];
	// So we can use the sorting class
	//Sorting Sort[COLOR="Yellow"][B]*[/B][/COLOR] = new Sorting(); 
        SortA = Sorting.SortMethodA(Permutation,size);//Sorting?
	System.out.println("The run-time of method A is; " + SortA[0]);
        }
        //

        public void MethodTwo()	{
	SortB = new int[size+1];
	// So we can use the sorting class
	//Sorting Sort[COLOR="Yellow"][B]*[/B][/COLOR] = new Sorting(); 
        SortB = Sorting.SortMethodB(Permutation,size);//Sorting?
	System.out.println("The run-time of method B is; " + SortB[0]);
        }
               
        public void MethodThree()	{
	SortC = new int[size+1];
	// So we can use the sorting class
	//Sorting Sort[COLOR="Yellow"][B]*[/B][/COLOR] = new Sorting(); 
        SortC = Sorting.SortMethodC(Permutation,size);//Sorting?
	System.out.println("The run-time of method C is; " + SortC[0]);
        }
        
        public void MethodFour()	{
	SortD = new int[size+1];
	// So we can use the sorting class
	//Sorting Sort[COLOR="Yellow"][B]*[/B][/COLOR] = new Sorting(); 
        SortD = Sorting.SortMethodD(Permutation,size);//Sorting?
	System.out.println("The run-time of method D is; " + SortD[0]);
        }  
        
// Random Method
	
public void RandomPermTwo()
    {
    int k;
    int NumberLeft;
    int temp;
    NumberLeft = size;
    while (NumberLeft>0)
      {
      counter2++;
      k = RandomSequence.nextInt(NumberLeft);
      temp = PermTwo[NumberLeft-1]; PermTwo[NumberLeft-1] = PermTwo[k]; PermTwo[k] = temp;
      NumberLeft--;
      };
    };
    
  public int[] GetPermTwo()
    {
    return PermTwo;
    };    
        
    public static void main(String[] args) {
        // TODO code application logic here
        }
    }

* = Cannot find symbol? :confused:
 
Last edited:
SortMethodA is defined in the sort.class file which is something that is already provided. And the class is saved in the same folder as Main.java. Netbeans acknowledges its existance...

I have tried loading it from command prompt too, but I get the same error :(
 
Thanks for the suggestion - but I'm getting the same errors again :(.

I think I have to slightly alter the properties of the files themselves. Though right clicking the class and java files in Netbeans doesn't allow me to do this (options are all greyed out) :/
 
I have just tried to create another class and copied the code over from the class file ;).

Sorting.SortMethodA(int,int); oddly enough appears to work...but obviously I'm not allowed to do this if you know what I mean..
 
Would it be ok to add you onto msn please? I appreciate if you're too busy but they're not huge classes or anything it's probably something I've just overlooked after staring at a computer screen for too long. My n1 ck is my username uncapitalised at hotmaledotcom. :)
 
Bump :( This still doesn't run properly. I showed the code to my tutor yesterday who said it was fine (but moved stuff around anyway). He got it to run through unix (exceed) but I've not been able to do it since :( Can anybody help please?
 
Back
Top Bottom