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
package marksstudent;
import java.util.Scanner;
public class MarksStudent {
static String[] populate(int n){
String [] names = new String[n];
System.out.println("Enter the names of the students\n");
Scanner scan = new Scanner(System.in);
for(int i=0; i<n; i++){
names[i] = scan.nextLine();
}
return names;
}
static int [][] marks(int n){
int [][] test = new int[n][3];
System.out.println("Enter the marks of the students\n");
Scanner scan = new Scanner(System.in);
for(int i=0; i<n; i++){
for(int j=0; j<3; j++){
test[i][j] = scan.nextInt();
}
}
return test;
}
static int [] display(int n){
String [] names= populate(n);
int [] [] tests = marks(n);
int [] results = new int [n];
int sum = 0;
System.out.printf("Name Test01 Test02 Test03 Final ");
System.out.printf("-------------------------------------");
for(int i =0; i<n; i++){
System.out.printf("%s\t", names[i]);
for(int j=0; j<3; j++){
System.out.printf("%d\t", tests[i][j]);
sum += tests[i][j];
}
System.out.printf("\n");
results[i] = sum / 3;
}
return results;
}
public static void main(String[] args) {
}
}
Comments
Leave a comment