IN JAVA Write the Java source code necessary to build a solu

IN JAVA
Write the Java source code necessary to build a solution for the problem below:You have just taken a new \"Teach for America\" job in a very rural, impoverished neighborhood. The school system does not provide you with any tools. You decide to write a new gradebook program. You need your new gradebook to allow you to sort the students by NAME or by highest grade on a test so that you can fill out all of the many district reports on your students\' progress. Remembering that sometimes Java lets you write one method and use it many times, you decide to write a generic method that will return the maximum and minimum element in a two-dimensional array (your gradebook, NAME, SCORE). Test the program using an array of random integers and again using an array of random names.
In order to do the comparison of names you need to understand the Java Character encoding scheme (Links to an external site.).
You should check this site to understand which character is bigger (\"A\" or \"Z\") and then work from there.
Print the array sorted by SCORE, then use it again and print the array sorted by NAME.

Solution


class Student
{
String name;
float grade;


Student(String n, float g)
{
name=n;
grade=g;
}
}
public class GradeBook
{
public static void sortByName(Student[] s)
{
Student temp;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if (s[i].name.compareTo(s[j].name)>0)
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
public static void sortByGrade(Student[] s)
{
Student temp;
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if (s[i].grade > s[j].grade)
{
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}


public static void main(String[] a)
{

Student[] s = new Student[5];

s[0]=new Student(\"Jimmy Br\",88);
s[1]=new Student(\"Garry Br\",68);
s[2]=new Student(\"Pierce\",97);
s[3]=new Student(\"Zimmer Jr\",85);
s[4]=new Student(\"Anderson Kr\",80);

System.out.println(\"Sort by name\ \");
sortByName(s);
for(int i=0; i<5;i++)
{
System.out.println(s[i].name+\" \\t\\t\"+s[i].grade);
}
  
  
System.out.println(\"Sort by name\ \");
sortByGrade(s);
for(int i=0; i<5;i++)
{
System.out.println(s[i].name+\" \\t\\t\"+s[i].grade);
}
}
}

IN JAVA Write the Java source code necessary to build a solution for the problem below:You have just taken a new \
IN JAVA Write the Java source code necessary to build a solution for the problem below:You have just taken a new \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site