Create a program with three methods/functions, The first one takes in n which is the size of an array then creates and populate the array with student names, the second method takes in n which is the size of an array then creates and populate n by 3 array with student marks(The three marks are for test 1 - 3) and finally a method that takes in the two arrays, calculates the final mark of all test and print out the results as indicated below: The first method should return and array of names and the second should return an array all test marks(i.e. 2d array with 3 columns). The third method in addition should also return an array for all the final marks
Name Test 01 Test 02 Test 03 Final
-------- --------- --------- --------- ---------
Gerry 55 55 55 55
public class Main {
public static String[] f1(int n, String studentName) {
String[] s = new String[n];
for (int i = 0; i < n; i++) {
s[i] = studentName;
}
return s;
}
public static int[] f2(int n) {
int[] s = new int[n];
for (int i = 0; i < n; i++) {
s[i] = 3;
}
return s;
}
public static void f3(int[] a, String[] b) {
for (int i = 0; i < a.length; i++) {
System.out.println(a[i] + "-" + b[i]);
}
}
}
Comments
Leave a comment