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

I already did the program but there are some errors. Can anyone help me? This is

ID: 647754 • Letter: I

Question

I already did the program but there are some errors. Can anyone help me? This is what the program is suppose to do.

Design and write an object-oriented program for managing student information. Your solution must consist of a class named Student that has a stores information pertaining to a student (ie name, student identification number, and etc.). There should be appropriate member functions available to communicate to a Student Member.

Additonally, the driver program should create a dynamic array instance of this class which is equal to the number of records in this data file. the first number in the file should indicate the number of records. Your driver program should take the Student object and perform all of the following:
Sort based on last name
Sort based on Student ID
Ask user to enter a Student ID number and return the user's information that matches that identification number.

Remember: You should display all the data before your first sort and after each Sort.
You should also remember to analyze the quicksort function and solve the recurrence relation.

This is the actual programming code.

//Student class that holds details of each student

public class Student

{

     String lname;

     String fname;

     String id;

     public Student(String ln,String fn, String idnum )

     {

          lname=ln;

          fname=fn;

          id=idnum;

     }

     //get methods to retrieve the values of instance variables

     public String getLname()

     {

          return lname;

     }

     public String getFname()

     {

          return fname;

     }

     public String getId()

     {

          return id;

     }

}

//import the required packages

//those are, io package to deal with files

//util package to deal with Scanner class

import java.util.*;

import java.io.*;

//driver class

public class QuickSortOnStudentData

{

     //main function

     public static void main(String args[])throws Exception

     {

          //declare the variables

          String fname;

          String lname;

          String id;

          String sid;

          //declare an array of size 30 of Student type

          Student sArray[]=new Student[30];

          //by using scanner object input read the data from

          //the file

          Scanner input=new Scanner(new FileReader(new File("StudentData")));

          //by using scanner object in read the data

          //from the console

          Scanner in=new Scanner(System.in);

          //declare a variable count

          int count=0;

          //loop to read each individual data

          //from the text file

          while(input.hasNext())

          {

              lname=input.next();

              fname=input.next();

              id=input.next();

              //create object ot Student class

              Student s=new Student(lname, fname, id);

              //add the object to the sArray

              sArray[count]=s;

              //increment the count

              count++;

          }

          //close the file

          input.close();

          //print the data present in the sArray before sorting

          System.out.println("The students details before sorting are: ");

          for(int i=0;i<count;i++)

              

System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId());

          System.out.println();

         

System.out.println("==========================================================");

          //print the data present in the sArray after calling the

          //quickSort so that the sArray is sort by last name

          System.out.println("Sort the array by last name using Quick sort: ");

          //call the quickSort

          quickSort(sArray , 0, count);

          for(int i=0;i<count;i++)

         {

              

System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId());

          }

          System.out.println();

         

System.out.println("==========================================================");

          //print the data present in the sArray after calling the

          //quickSort1 so that the sArray is sort by id

          System.out.println("Sort the array by id using Quick sort: ");

          quickSort1(sArray, 0, count);

          for(int i=0;i<count;i++)

          {

System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId())

          }

          System.out.println();

System.out.println("==========================================================");

          //prompt the user to enter an id to search and

          //print the details

          System.out.println(" Enter the Id of the student to search: ");

          sid=in.next();

          //call the seachId function and store the return index value in index variable

          int index=searchId(sArray, count, sid);

          //display the student details whose index is found

          System.out.println("The student details at ["+(index+1)+"] are: ");

System.out.println(sArray[index].getLname()+" "+sArray[index].getFname()+" "+sArray[index].getId());

     }

     //partition method to get the pivot value and sort the data

     public static int partition(Student[] a, int beg, int end)

     {

          int p=beg;

          Student pivot=a[beg];

          //for loop to retrieve the pivot element

          for(int j=beg+1;j<end;j++)

          {

              if(pivot.getLname().compareTo(a[j].getLname())>0)

              {

                   a[p]=a[j];

                   a[j]=a[p+1];

                   a[p+1]=pivot;

                   p=p+1;

              }

          }

          return p;

     }

     //quickSort function

     public static void quickSort(Student a[], int beg, int end

     {

          if(beg<end)

          {

              //retrieving the pivot element

              int p=partition(a,beg,end);

              //calling the self quickSort function

              quickSort(a,beg,p-1);

              quickSort(a,p+1,end);

          }

     }

     //quick sort function to sort by id

     public static void quickSort1(Student a[], int beg, int end)

     {

          if(beg<end)

          {

              //retrieving the pivot element

              int p=partition1(a,beg,end);

              //calling the self quickSort function

            quickSort1(a,beg,p-1);

              quickSort1(a,p+1,end);   

          }

     }

     //partition to sort the array by id

     public static int partition1(Student[] a, int beg, int end)

     {

          int p=beg;

Student pivot=a[beg];

          //for loop to retrieve the pivot element

          for(int j=beg+1;j<end;j++)

          {

              if(pivot.getId().compareTo(a[j].getId())<0)

              {

                   a[p]=a[j];

                   a[j]=a[p+1];

                   a[p+1]=pivot;

                   p=p+1;

              }

          }

          return p;

     }

     //searchid method to search the respective id and

     //return its index

     public static int searchId(Student a[],int size, String id)

     {

          int ind=0;

          for(int i=0;i<size;i++)

          {

              if(a[i].getId().equals(id))

              {

ind=i;

              }

          }

          return ind;

     }

}

Explanation / Answer

//import the required packages

//those are, io package to deal with files

//util package to deal with Scanner class

import java.util.*;

import java.io.*;


class Student

{

String lname;

String fname;

String id;

public Student(String ln,String fn, String idnum )

{

lname=ln;

fname=fn;

id=idnum;

}

//get methods to retrieve the values of instance variables

public String getLname()

{

return lname;

}

public String getFname()

{

return fname;

}

public String getId()

{

return id;

}

}
  
//driver class

public class QuickSortOnStudentData

{

//main function

public static void main(String args[])throws Exception

{

//declare the variables

String fname;

String lname;

String id;

String sid;

//declare an array of size 30 of Student type

Student sArray[]=new Student[30];

//by using scanner object input read the data from

//the file

Scanner input=new Scanner(new FileReader(new File("StudentData.txt")));

//by using scanner object in read the data

//from the console

Scanner in=new Scanner(System.in);

//declare a variable count

int count=0;

//loop to read each individual data

//from the text file

while(input.hasNext())

{

lname=input.next();

fname=input.next();

id=input.next();

//create object ot Student class

Student s=new Student(lname, fname, id);

//add the object to the sArray

sArray[count]=s;

//increment the count

count++;

}

//close the file

input.close();

//print the data present in the sArray before sorting

System.out.println("The students details before sorting are: ");

for(int i=0;i<count;i++)

  
System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId());

System.out.println();


System.out.println("==========================================================");

//print the data present in the sArray after calling the

//quickSort so that the sArray is sort by last name

System.out.println("Sort the array by last name using Quick sort: ");

//call the quickSort

quickSort(sArray , 0, count);

for(int i=0;i<count;i++)

{

  
System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId());

}

System.out.println();


System.out.println("==========================================================");

//print the data present in the sArray after calling the

//quickSort1 so that the sArray is sort by id

System.out.println("Sort the array by id using Quick sort: ");

quickSort1(sArray, 0, count);

for(int i=0;i<count;i++)

{
System.out.println(sArray[i].getLname()+" "+sArray[i].getFname()+" "+sArray[i].getId());
}
System.out.println();

System.out.println("==========================================================");
//prompt the user to enter an id to search and
//print the details
System.out.println(" Enter the Id of the student to search: ");
sid=in.next();
//call the seachId function and store the return index value in index variable
int index=searchId(sArray, count, sid);
//display the student details whose index is found
System.out.println("The student details at ["+(index+1)+"] are: ");
System.out.println(sArray[index].getLname()+" "+sArray[index].getFname()+" "+sArray[index].getId());
}
//partition method to get the pivot value and sort the data
public static int partition(Student[] a, int beg, int end)
{
int p=beg;
Student pivot=a[beg];
//for loop to retrieve the pivot element
for(int j=beg+1;j<end;j++)
{
if(pivot.getLname().compareTo(a[j].getLname())>0)
{
a[p]=a[j];
a[j]=a[p+1];
a[p+1]=pivot;
p=p+1;
}
}
return p;
}
//quickSort function
public static void quickSort(Student a[], int beg, int end)
{
if(beg<end)
{
//retrieving the pivot element
int p=partition(a,beg,end);
//calling the self quickSort function
quickSort(a,beg,p-1);
quickSort(a,p+1,end);
}
}
//quick sort function to sort by id
public static void quickSort1(Student a[], int beg, int end)
{
if(beg<end)
{
//retrieving the pivot element
int p=partition1(a,beg,end);
//calling the self quickSort function
quickSort1(a,beg,p-1);
quickSort1(a,p+1,end);   
}
}
//partition to sort the array by id
public static int partition1(Student[] a, int beg, int end)
{
int p=beg;
Student pivot=a[beg];
//for loop to retrieve the pivot element
for(int j=beg+1;j<end;j++)
{
if(pivot.getId().compareTo(a[j].getId())<0)
{
a[p]=a[j];
a[j]=a[p+1];
a[p+1]=pivot;
p=p+1;
}
}
return p;
}
//searchid method to search the respective id and
//return its index
public static int searchId(Student a[],int size, String id)
{
int ind=0;
for(int i=0;i<size;i++)
{
if(a[i].getId().equals(id))
{
ind=i;
}
}
return ind;
}
}