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

Write a program that uses a structure to store the following student data items:

ID: 3815950 • Letter: W

Question

Write a program that uses a structure to store the following student data items:

First Name

Last Name

Student ID (10 digit integer – store as long int)

Major

GPA (double)

The program should allow the user to enter data for up to twenty students, the data should be stored in an array of the structure type described above.

The program should sort the array elements in ascending order by the student’s last name and first name. Modify the selectionSort function provided in the sample program Demo_selectionSort.c to perform the sort. After sorting the array, display a table that shows the student data in a table with the following column headings in order: Last Name, First Name, Student ID, Major and GPA.

Explanation / Answer

package Student;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/////////////////////////////// class first containing sub methods called in main class thait is the class contains main method

public class Student {
   Student[] student = new Student[20];
   BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
  
   private String First_Name;
   private String Last_Name;
   private String Major;
   private long Student_Id;
   private double GPA;
   static int a = 0;
   Student(){
      
   }
   Student(String first_name, String last_name, String major,long student_id, double GPA ){
       this.First_Name = first_name;
       this.Last_Name = last_name;
       this.Major = major;
       this.Student_Id = student_id;
       this.GPA = GPA;
   }
   public void input() throws IOException{
       for(int i = 0 ; i < student.length ; i++){
       System.out.println("Please Enter First Name : ");
       String fname = scanner.readLine();
      
       System.out.println("Please Enter Last Name : ");
       String lname = scanner.readLine();
      
       System.out.println("Please Enter Student ID : ");
       long id = Long.parseLong(scanner.readLine());
      
       System.out.println("Please Enter Major : ");
       String major = scanner.readLine();
      
       System.out.println("Please Enter GPA : ");
       double gpa = Double.parseDouble(scanner.readLine());
       Student stu = new Student(fname, lname, major, id, gpa);
       student[i] = stu;
       }
       a = 1;
   }
   public void output(){
       if(a == 0){
           System.out.println("Please add 'Initial' books first !");
       }else{
           System.out.println(" Last Name "+" | "+"First Name "+" | "+" Major "+" | "+" Student ID "+" | "+" GPA ");
       for( int i = 0;i < student.length ; i++ ){
          
           System.out.println((i+1+" | "+student[i].Last_Name+" | "+student[i].First_Name+" | "+student[i].Major+" | "+student[i].Student_Id+" | "+student[i].GPA));
           }
       }
  
   }

}

/////////////////////////////// class second containing main method..

class Out{

   public static void main(String[] args) {
       char ch = 'a';
       Scanner scanner = new Scanner(System.in);
       Student student = new Student();
       do{
      
       System.out.println("1. insert the details of student.");
       System.out.println("2. show list of students.");
       System.out.println("Enter Option no :");
      int choice = scanner.nextInt();
      
       switch(choice){
       case 1 :
           Student.input();
           break;
          
       case 2 :
           try{
           Student.output();
           }
           catch(Exception e)
           {
               System.out.println("Somewhere you entered 'WRONG value' please add again");
           }
           break;
       default : System.out.println("Wrong Entry ");
       break;
      
   }while(ch=='Y' || ch=='y');
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote