Summary

This assignment has two primary tasks,

  • Implementing a Student class
  • Searching for a student in an array of Student objects read from a le. (The input part has been completed in the template).
  • Sorting the array of Student objects based on certain criteria

Learning Outcomes

The second assignment assesses students skills on the following topics,

  • Designing and implementing classes.
  • Object declaration, instantiation and operating on the same.
  • Creating and operating on arrays of objects.
  • Searching.
  • Sorting.

Explanation of tasks

STEP 1

Your rst task is to complete the Student class by adding the following,

  • getters
  • setters
  • parameterized constructor (default constructor not required)
  • compareTo(Student)
  • equals(Student)
  • toString()

We have deliberately not provided the method headers (except that for the constructor). The requirements for each method is provided in the Student.java le and you are required to add the methods based on the comments. Also, the JUnit test class StudentTest invokes methods from Student. You can use those method invocations as hints to complete the methods of Student class. We suggest you complete the methods in three steps,

  • Complete only the the headers (no method body).
  • Depending on return types, add a return statement so that the class doesnt have compilation errors. For example, if the return type is boolean, add the statement return false. Save the le.
  • Ifthesecondstepisperformedcorrectly,allcompilationerrors(redcrosses)inStudentTest will disappear. Then only, proceed on to completing the method bodies. We suggest completing the method bodies in the order specied above.

STEP 2: Test the Student class

Test the Student class by running the JUnit tests in StudentTest. Also, run the class Client.java. If step 1 has been nished correctly, you should get two sets of displays, raw, and sorted, which are the same for now because the sort methods have not been completed.

STEP 3: Searching and Sorting

Complete the following methods (in the suggested order) in class StudentArrayService.

  • linearSearch
  • isDescendingSorted
  • descendingSort
  • binarySearch

The method headers are provided for this class and above them the method requirements are stated.

Please note that sorting is based on the compareTo method from Student class. Thus, s1.compareTo(s2) == 1impliesthatstudents1ismorethan students2. Similarly,s1.compareTo(s2) == -1 implies that student s1 is less than student s2. And nally s1.compareTo(s2) == 0 implies that student s1 and student s2 are the same in terms of sorting.

Template

You are provided with a template for the project. Import the project into Eclipse. As you complete the methods, you can test the correctness of your solutions using the JUnit tests provided in the StudentTest.java and StudentArrayServiceTest.java classes. Please note that the setup() method in the test classes runs before every other test method.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.