Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please make a simple sorting program with the following conditions: 1. At the be

ID: 3583020 • Letter: P

Question

Please make a simple sorting program with the following conditions: 1. At the beginning of the program, user will be asked to input the number of students. Validate the number of the students must be between 5 and 10 2. Then the program will ask user to input Student Name and Student Mark as many as the number of students that he/she input before. Validate the Student Name length must be between 1 and 20 characters, and the Student Mark must be between 0 and 100. 3. After user input the data, then the program will be display the Student Data. 4. Then display the following menu: 1. Ascending sort by score 2. Descending sort by score 3. Ascending sort by name 4. Descending sort by name 5. Exit 5. If user choose menu '1', then the student data in ascending sort based on score. 6. If user choose menu '2', then the student data in descending sort based on score. 7. If user choose menu '3', then the student data in ascending sort based on name. 8. If user choose menu '4', then the student data in descending sort based on name. f user choose menu '5', then the program will ends Please run the EXE file to see the sample program. Print Screen of the Program when Ask User to Input Data Selection Sort Input the number of s tudent C5 101 Input Student Na Student No 1 20] Adi Input Student Mark. Student No 1 t0. 1001 90 Input Student Name Student No 2 [1 20] Rudi Input Student Mark. Student No 2 1001 96 Input Student Name Student No 3 [1 20 Candi Input Student Mark Student No 3 100 J 23 Input Student Name Student No 4 [1..20 J Santi Input Student Mark, Student No 4 L2. 1001 95 Input Student Name Student No 5 [1 20 Budi Input Student Mark Student No 5 [0 -1001 56 Print Screen of the Program when User Display Student Data and Main Menu Student Data No Name Mark Adi 90 Rudi 96 Candi 23 Santi 95 Budi. 56 Menu Ascending sort b Student Mark Descending sort by student Mark Ascending s Student Descending sort by Student Name Exit In ut choice

Explanation / Answer

SelectionSort.java

import java.util.Scanner;

public class SelectionSort {

   public static void main(String[] args) {
       int no_of_students;
       String stdname;
       int grad;
       //Scanner class object is used to read the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
               while(true)
               {
               System.out.print("Input No of Students [5..10] :");
               no_of_students=sc.nextInt();
               if (no_of_students<5 || no_of_students>10) {
                   System.out.println("** Invalid.Must be between 5 and 10 **");
                   continue;
               }
               else
                   break;
               }
              
               String names[]=new String[no_of_students];
               int grades[]=new int[no_of_students];
               for(int i=0;i<no_of_students;i++)
               {
                   sc.nextLine();
                   while(true)
                   {
                       System.out.print(" Input Student Name ,Student No "+(i+1)+"[1..20] :");
                       stdname=sc.nextLine();
                       if(stdname.length()<1 || stdname.length()>20)
                       {
                           System.out.println("** Invalid.Name must be between [1-20] **");
                           continue;
                       }
                       else
                       {
                           names[i]=stdname;
                           break;
                       }  
                   }
                  
         
                   while(true)
                   {
                       System.out.print("Input Student Mark ,Student No "+(i+1)+"[0..100] :");
                       grad=sc.nextInt();  
                       if(grad<0 || grad>100)
                       {
                           System.out.println("** Invalid.Grade must be between [0-100] **");
                           continue;
                       }
                       else
                       {
                           grades[i]=grad;
                           break;
                       }  
                   }  
               }

               display(names,grades,no_of_students);
      
              
               int choice;
  
              
               while(true)
               {
                   System.out.println(" Menu :");
                   System.out.println("1.Ascending Sort by Student Mark");
                   System.out.println("2.Decending Sort by Student Mark");
                   System.out.println("3.Ascending Sort by Student Name");
                   System.out.println("4.Decending Sort by Student Name");
                   System.out.println("5.Exit");
                   System.out.println("Input Choice :");
                   choice=sc.nextInt();
                   switch(choice)
                   {
                   case 1:{
                       //This Logic will Sort the Array of elements in Ascending order
                       int temp;
                       for (int i = 0; i < no_of_students; i++)
                   {
                   for (int j = i + 1; j < no_of_students; j++)
                   {
                   if (grades[i] > grades[j])
                   {
                   temp = grades[i];
                   grades[i] = grades[j];
                   grades[j] = temp;
                   }
                   }
                   }
                       display(names,grades,no_of_students);
                       continue;
                   }
                   case 2:{
                       //This Logic will Sort the Array of elements in Ascending order
                       int temp;
                       for (int i = 0; i < no_of_students; i++)
                   {
                   for (int j = i + 1; j < no_of_students; j++)
                   {
                   if (grades[i] < grades[j])
                   {
                   temp = grades[i];
                   grades[i] = grades[j];
                   grades[j] = temp;
                   }
                   }
                   }
                       display(names,grades,no_of_students);
                           continue;
                   }
                   case 3:{
          
                       //This Logic will Sort the Array of elements in Ascending order
                       String temp1;
                       for (int i = 0; i < no_of_students; i++)
                   {
                   for (int j = i + 1; j < no_of_students; j++)
                   {
                   if (names[i].compareTo(names[j])>0)
                   {
                   temp1 = names[i];
                   names[i] = names[j];
                   names[j] = temp1;
                   }
                   }
                   }
                       display(names,grades,no_of_students);
                           continue;
                   }
                   case 4:{
                       //This Logic will Sort the Array of elements in Ascending order
                       String temp1;
                       for (int i = 0; i < no_of_students; i++)
                   {
                   for (int j = i + 1; j < no_of_students; j++)
                   {
                   if (names[i].compareTo(names[j])<0)
                   {
                   temp1 = names[i];
                   names[i] = names[j];
                   names[j] = temp1;
                   }
                   }
                   }
                       display(names,grades,no_of_students);
                           continue;
                   }
                   case 5:{
                       break;
                   }
                   }
                       break;  
               }
              

   }

   private static void display(String[] names, int[] grades, int no_of_students) {
       System.out.println("Student Data :");
       System.out.println("--------------------------------------");
       System.out.println("| No | Name | Mark |");
       for(int i=0;i<no_of_students;i++)
       {
          
           System.out.printf("| %d | %-35s| %d | ",(i+1),names[i],grades[i]);
       }
       System.out.println("--------------------------------------");
      
   }

}

__________________________

Output:

Input No of Students [5..10] :5

Input Student Name ,Student No 1[1..20] :Adi
Input Student Mark ,Student No 1[0..100] :90

Input Student Name ,Student No 2[1..20] :Rudi
Input Student Mark ,Student No 2[0..100] :96

Input Student Name ,Student No 3[1..20] :Candi
Input Student Mark ,Student No 3[0..100] :23

Input Student Name ,Student No 4[1..20] :Santi
Input Student Mark ,Student No 4[0..100] :95

Input Student Name ,Student No 5[1..20] :Budi
Input Student Mark ,Student No 5[0..100] :56
Student Data :
--------------------------------------
| No | Name | Mark |
| 1 | Adi | 90 |
| 2 | Rudi | 96 |
| 3 | Candi | 23 |
| 4 | Santi | 95 |
| 5 | Budi | 56 |
--------------------------------------


Menu :
1.Ascending Sort by Student Mark
2.Decending Sort by Student Mark
3.Ascending Sort by Student Name
4.Decending Sort by Student Name
5.Exit
Input Choice :
1
Student Data :
--------------------------------------
| No | Name | Mark |
| 1 | Adi | 23 |
| 2 | Rudi | 56 |
| 3 | Candi | 90 |
| 4 | Santi | 95 |
| 5 | Budi | 96 |
--------------------------------------


Menu :
1.Ascending Sort by Student Mark
2.Decending Sort by Student Mark
3.Ascending Sort by Student Name
4.Decending Sort by Student Name
5.Exit
Input Choice :
2
Student Data :
--------------------------------------
| No | Name | Mark |
| 1 | Adi | 96 |
| 2 | Rudi | 95 |
| 3 | Candi | 90 |
| 4 | Santi | 56 |
| 5 | Budi | 23 |
--------------------------------------


Menu :
1.Ascending Sort by Student Mark
2.Decending Sort by Student Mark
3.Ascending Sort by Student Name
4.Decending Sort by Student Name
5.Exit
Input Choice :
3
Student Data :
--------------------------------------
| No | Name | Mark |
| 1 | Adi | 96 |
| 2 | Budi | 95 |
| 3 | Candi | 90 |
| 4 | Rudi | 56 |
| 5 | Santi | 23 |
--------------------------------------


Menu :
1.Ascending Sort by Student Mark
2.Decending Sort by Student Mark
3.Ascending Sort by Student Name
4.Decending Sort by Student Name
5.Exit
Input Choice :
4
Student Data :
--------------------------------------
| No | Name | Mark |
| 1 | Santi | 96 |
| 2 | Rudi | 95 |
| 3 | Candi | 90 |
| 4 | Budi | 56 |
| 5 | Adi | 23 |
--------------------------------------


Menu :
1.Ascending Sort by Student Mark
2.Decending Sort by Student Mark
3.Ascending Sort by Student Name
4.Decending Sort by Student Name
5.Exit
Input Choice :
5

_____________Thank You