Using the above code add a method that takes in three arrays, one for student names, one for final test marks and a last one for assignment mark. The method should then calculate the students qualifying mark (a student needs 50 or more to qualify) using the following weights: 40% of the test and 60% of the assignment, finally print out whether the person qualified or not
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
package com.company;
public class Main {
//This function calculates the qualifying marks and tells whether a student has qualified or not
public static void qualifying_students(String [] student_names, double [] final_test_mark, double [] assignment_mark) {
int arrays_length = student_names.length;
System.out.println("\n");
for(int i = 0; i<arrays_length;i++)
{
//calculate the mark of the student
double assignment = (0.6)*assignment_mark[i];
double final_test = (0.4)*final_test_mark[i];
double qualify = assignment + final_test;
if(qualify == 50 || qualify>50)
{
System.out.println(student_names[i]+" got "+qualify+" and has qualified");
}
else
{
System.out.println(student_names[i]+" got "+qualify+" and has not qualified");
}
}
}
public static void main(String[] args) {
String [] student_names = {"kelly","daniel","Nyamai","steve","Stella"};
double [] final_test = {70, 80, 49, 85,60};
double [] assignment = {50, 60, 45, 75, 25};
//Let us write the main method and call our students_qulaify method
qualifying_students(student_names,final_test,assignment);
}
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment