I’m doing lately so much C++ that I forgot how to use Java. I’m confused with the includes of C++ what Java doesn’t have. I’ve googled but always finds something like import but that doesn’t work and making an object but this isn’t possible because it’s a library.
I’ve got a class A : with something like this:
class Library
{
int findMaximum(int [] table)
{
int max = 0;
for( int i = 0; i < table.length; i++)
{
if( table[i] > max )
max = table[i];
}
return max;
}
}
and so much more functions.
And I’ve got a class B:
class Tdd_1{
static boolean test1(){
int [] table = new int[20];
for(int i = 0; i < table.length; i++)
table[i] = (int)(Math.random()*100)+1;
findMax(table);
return true;
}
}
Now I can’t use findmax in that class? How can I fix this? The files are in the same dir?
Then eventually the purpose is to have one main file like:
public static void main(String[] args)
{
System.out.println("Test 1: \n");
if(test1())
System.out.println("Passed.\n");
else
System.out.println("Failed.\n");
}
where I can run test1 and all the others….
Can someone help me?
Kind regards;
What is a test case where I can
You need to instantiate The Library class first before you can invoke its methods.
Or declare
findMaximumas static like so:and access it like so: