Answer to Question #262598 in Java | JSP | JSF for dee

Question #262598

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


1
Expert's answer
2021-11-08T17:37:10-0500
import java.util.Arrays;
import java.util.Scanner;
public class Student {
 String [] N(int name){
 System.out.println("Input the student names\n");
 Scanner input = new Scanner(System.in);
 String [] stuN = new String[name];
 for(int x=0; x<name; x++){
 System.out.println("Name "+(x+1));
 stuN[x] = input.nextLine();
 }
 return stuN;
 }
 int [][] marks(int name){
 int [][] stuMark = new int[name][3];
 for(int x=0; x<name; x++){
 for(int y=0; y<3; y++){
 System.out.println("Input test mark: "+(y+1));
 
 Scanner input = new Scanner(System.in);
 stuMark[x][y] = input.nextInt();
 }
 }
 
 return stuMark;
 }
 int [] display(String stuN[], int stuMark[][]){
 System.out.println("Name Test 01 Test 02 Test 03 Final");
 System.out.println("---- ------- ------- -------- ---------");
 int [] totalMarks = new int[stuN.length];
 for(int x=0; x<stuN.length; x++){
 int sum = 0;
 System.out.print("%s ",stuN[x]);
 for(int y=0; y<3; y++){
 System.out.print("%d ",stuMark[x][y]); 
 sum += stuMark[x][y];
 }
 System.out.print("%d ",sum /3);
 totalMarks[x] = sum /3;
 }
 return totalMarks;
 }
 public static void main(String[] args) {
 Student S = new Student();
 int [] results = S.display(S.N(1), S.marks(1));
 System.out.println(Arrays.toString(results));
 }
 
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS