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

Specifically, you are given the following code: class GenericRegistry, class Stu

ID: 3850809 • Letter: S

Question

Specifically, you are given the following code:

class GenericRegistry, class Student, application class Lab4

And you need to supply the code for the following classes and interfaces:

interface Registry, class StudentRegistry

public abstract class GenericRegistry implements Registry {

       protected Comparable[] members;

       protected int count;

       public void addMember(Comparable object) {

              members[count++] = object;

       }

// Selection sort

       public void sort() {

              for (int i = 0; i < count - 1; i++) {

                     int min = i;

                     for (int j = i + 1; j < count; j++) {

                           if (members[min].compareTo(members[j]) > 0) {

                                  min = j;

                           }

                     }

                     Comparable object = members[i];

                     members[i] = members[min];

                     members[min] = object;

              }

       }

}

Note: the storage in this class is an array of Comparable objects. Thus, any objects to be stored in the array should be a type of Comparable. Since Student implements Comparable, thus Student can be stored in the array as well.

public class Student implements Comparable {

       private String name;

       private String major;

       public Student(String name, String major) {

              this.name = name;

              this.major = major;

       }

       public String getName() {

              return name;

       }

       public String getMajor() {

              return major;

       }

       public int compareTo(Object student) {

              return name.compareTo(((Student) student).name);

       }

       public String toString() {

              return "Name: " + name + " major " + major;

       }

}

Note: this class implements the Comparable interface. Thus, it can be stored in the array called “members” in the GenericRegistry. An interface is also a type. When a class implements an interface, the class will have two types. In this case, the class Student is both a type of Student and a type of Comparable.

public class Lab4 {

       public static void main(String[] s) {

              StudentRegistry sr = new StudentRegistry(10);

              sr.addMember(new Student("Close", "English"));

              sr.addMember(new Student("Snow", "Physics"));

              sr.addMember(new Student("Lal", "Physics"));

              sr.addMember(new Student("Chow", "English"));

              sr.print();

              sr.sort();

              System.out.println();

              sr.print();

       }

}

Note: we allocate 10 cells for the array members. This is the largest number of Student objects that can be stored in the array. When you write the print() method for the class StudentRegistry, you should use the instance variable count in the class GenericRegistry to decide the actual number of items in the array members (not the array length!).

Explanation / Answer

the interface Registry can code 2 ways.

Registry.java

One way:

public interface Registry{
   void addMember(Comparable object);
}

Other way:

public interface Registry{
   void addMember(Comparable object);
   void sort();
}

StudentRegistry.java

public class StudentRegistry extends GenericRegistry{
   public StudentRegistry(int capacity){
       super.members = new Student[capacity];
   }
   public void print(){
       for(int i=0;i<super.count;i++)
       System.out.print(super.members[i]+"   ");
       System.out.println();
   }
}


Thankyou.

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