Answer:
I have written the Java code based on your requirements.
I have used BinarySearchTree to get the results that You want.
The code is working perfectly and it has no-error.
I also attached the output screen-shot that I got by running the below program.
Output:
Code:
test.java :
import java.io.*;
import java.util.*;
class BST
{
class Node
{
String first_name,sur_name;
double average;
Node left,right;
public Node(String
first_name,String sur_name,double average)
{
this.first_name=first_name;
this.sur_name=sur_name;
this.average=average;
left=right=null;
}
}
Node root;
BST()
{
root=null;
}
void insert(String first_name,String sur_name,double
average)
{
root=insert_data(root,first_name,sur_name,average);
}
Node insert_data(Node root,String first_name,String
sur_name,double average)
{
if(root==null)
{
root=new
Node(first_name,sur_name,average);
return
root;
}
if(average < root.average)
{
root.left=insert_data(root.left,first_name,sur_name,average);
}
else if(average >=
root.average)
{
root.right=insert_data(root.right,first_name,sur_name,average);
}
return root;
}
void print(double class_average)
{
print_function(root,class_average);
}
void print_function(Node root,double
class_average)
{
if(root!=null)
{
print_function(root.left,class_average);
if(root.average>=class_average)
{
System.out.println("\n");
System.out.println(root.first_name+"
"+root.sur_name+" "+root.average+" ");
}
print_function(root.right,class_average);
}
}
}
public class test
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
BST tree=new BST();
int n=sc.nextInt();
sc.nextLine();
int count=n;
double sum=0;
while(n>0)
{
String
s=sc.nextLine();
String[]
arr=s.split(" ");
double
quize=Double.parseDouble(arr[2]);
double
homework=Double.parseDouble(arr[3]);
double
project=Double.parseDouble(arr[4]);
double
midterm=Double.parseDouble(arr[5]);
double
final_exam=Double.parseDouble(arr[5]);
double
average=(double)((0.15*quize)+(0.15*homework)+(0.20*project)+(0.25*midterm)+(0.25*final_exam));
tree.insert(arr[0],arr[1],average);
sum=sum+average;
System.out.println(" ");
n--;
}
double
class_average=(double)(sum/count);
System.out.println("\n\nClass
Average Mark : "+class_average);
System.out.println("\n\nMarks which
are greater tha or equal to "+class_average+" is below:");
tree.print(class_average);
}
}
solve in java using Eclipse Question 6 Given a student information: Name, Surname, Quiz grade, Homework...