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.

** please use a two dimensional array for the gradebook and generic method

Solution

import java.util.*;

public class StudentSortApp {
   public static void main(String[] args) {
       System.out.println(\"Welcome to the Student Scores Application.\" + \"\ \");
       Scanner sc = new Scanner(System.in);
       System.out.print(\"Enter number of students to enter: \");
       int numberofStudents = sc.nextInt();

       // arrays storing student name and score
       Student[] students = new Student[numberofStudents];
       StudentScore[] studentScores = new StudentScore[numberofStudents];

       int t = 0;
       for (int i = 0; i < numberofStudents; i++) {
           System.out.println(\"\");
           String studentLastName = Validator.lastName(sc, \"Student \"
                   + (i + 1) + \" Last name: \");
           String studentFirstName = Validator.lastName(sc, \"Student \"
                   + (i + 1) + \" First name: \");
           int studentScore = Validator.validScore(sc, \"Student \" + (i + 1)
                   + \" score : \");

           students[t] = new Student(studentFirstName, studentLastName,
                   studentScore);
           studentScores[t] = new StudentScore(studentFirstName,
                   studentLastName, studentScore);
           t = t + 1;

       }
       // output
       System.out.println(\"\");
       System.out.println(\"Last Name Sort\");
       Arrays.sort(students, 0, numberofStudents);
       for (Student i : students)
           System.out.println(i.getlastName() + \", \" + i.getfirstName() + \": \"
                   + i.getScore());

       System.out.println();
       System.out.println(\"Score Sort\");
       Arrays.sort(studentScores);
       for (StudentScore i : studentScores)
           System.out.println(i.getlastName() + \", \" + i.getfirstName() + \": \"
                   + i.getScore());

   }
}

import java.util.Scanner;

public class Validator {
   public static int validScore(Scanner sc, String prompt) {
       int studentScore = 0;
       boolean isValid = false;

       while (isValid == false) {
           System.out.print(prompt);
           studentScore = sc.nextInt();
           if (studentScore > 100 || studentScore < 0) {
               System.out
                       .println(\"Error! You have to enter a score between 0 and 100\");
           } else {
               isValid = true;
           }

       }
       return studentScore;

   }

   public static String lastName(Scanner sc, String prompt) {
       Scanner input = new Scanner(System.in);
       String StudentName = \"\";
       boolean isvalid = false;

       while (isvalid == false) {

           System.out.print(prompt);
           StudentName = input.nextLine();
           if (StudentName == null || StudentName.equals(\"\")) {
               System.out.println(\"Error! You have to enter a name.\");
           }

           else

           {
               isvalid = true;

           }

       }
       return StudentName;

   }

}

public class Student implements Comparable {

   private String firstName = \"\";
   private String lastName = \"\";
   private int score = 0;

   // Student Class constructor
   public Student(String firstName, String lastName, int score)

   {
       this.firstName = firstName;
       this.lastName = lastName;
       this.score = score;
   }

   public int compareTo(Object nextStudent) {
       Student student = (Student) nextStudent;

       if (lastName.equals(student.lastName)) {
           return firstName.compareToIgnoreCase(student.firstName);
       }
       return lastName.compareToIgnoreCase(student.lastName);

   }

   // returns first Name
   public String getfirstName() {
       return firstName;
   }

   // Returns Last Name
   public String getlastName() {
       return lastName;
   }

   // Returns Student Score
   public int getScore() {
       return score;
   }
}

public class StudentScore implements Comparable<StudentScore> {
   private String firstName = \"\";
   private String lastName = \"\";
   private int score = 0;

   // StudentScore constructor
   public StudentScore(String firstName, String lastName, int score) {
       this.firstName = firstName;
       this.lastName = lastName;
       this.score = score;
   }

   public int compareTo(StudentScore nextStudent)

   {
       return Integer.compare(this.score, nextStudent.score);

   }

   // returns first Name
   public String getfirstName() {
       return firstName;
   }

   // Returns Last Name
   public String getlastName() {
       return lastName;
   }

   // Returns Student Score
   public int getScore() {
       return score;
   }
}

output

Welcome to the Student Scores Application.

Enter number of students to enter: 4

Student 1 Last name: mark
Student 1 First name: smith
Student 1 score : 98

Student 2 Last name: koti
Student 2 First name: b
Student 2 score : 10

Student 3 Last name: john
Student 3 First name: abraham
Student 3 score : 65

Student 4 Last name: ramu
Student 4 First name: rma
Student 4 score : 25

Last Name Sort
john, abraham: 65
koti, b: 10
mark, smith: 98
ramu, rma: 25

Score Sort
koti, b: 10
ramu, rma: 25
john, abraham: 65
mark, smith: 98

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 \
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