When I'm working on homework assignments for class it is typically beneficial if the programs are small to keep the problem to a single class (easy to submit with our script).
For these one-off programs does it make more sense to declare all methods and instance variables as static or does it make more sense to declare an instance of the class itself in the main method?
So, for example:
A.
public class MergeSort
{
public static Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
int[] randData = getRandomData();
int[] sortedData = mergeSort(randData);
}
public static int[] mergeSort(int[] unsortedData)
{
// ...
}
public static int[] merge(int[] data, int a, int b, int c)
{
// ...
}
}
vs
B.
public class MergeSort
{
public Scanner input = new Scanner(System.in);
public static void main(String[] args)
{
MergeSort ms = new MergeSort();
int[] randData = ms.getRandomData();
int[] sortedData = ms.mergeSort(randData);
}
public int[] mergeSort(int[] unsortedData)
{
// ...
}
public int[] merge(int[] data, int a, int b, int c)
{
// ...
}
}