Problem 1 (25 points) The Registrar's office is asked to generate several reports for enrolled students at the Universit

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Problem 1 (25 points) The Registrar's office is asked to generate several reports for enrolled students at the Universit

Post by answerhappygod »

Problem 1 25 Points The Registrar S Office Is Asked To Generate Several Reports For Enrolled Students At The Universit 1
Problem 1 25 Points The Registrar S Office Is Asked To Generate Several Reports For Enrolled Students At The Universit 1 (127.37 KiB) Viewed 51 times
Problem 1 (25 points) The Registrar's office is asked to generate several reports for enrolled students at the University. These reports are to list the student's name and id number (separated with a */) along with their Major, Gpa, and projected graduation year (classof). Part 1 Create a class called Student to hold individual Student information that includes: name - (String) - the full name of the student id (int) - The student id major - (String) - The major of the student gpa (double) - The grade point average of the student classOf (int) - Projjected graduation year Add getters and setters for the 5 members of the class. The President asks for a report of all students and he wants it sorted by 2 criteria: Major and Gpa. Specifically, he says 'please sort it by descending Gpa within Major'. Note that this is a tiered sort with 2 criteria. So all of the students with the same major are together in the sorted list. Within the groups of students for a specific major ((i.e. CS, TSM, etc), that group is sorted by descending Gpa. You can start with the Selection Sort code provided in Selection.java. However, your task is to craft a compareTo() method that will properly sort the students by the double criteria. Remember, you are only allowed a single compareTo so you will have to figure out how to look at both at once to determine ordering! Also, write a toString() method to return a string of the form: (major : gpa : classOf: name/id) Note that we are printing the two fields on which we are sorting at the beginning of the line so the President can easily see the groups of students and their ranking within the major! Implement this class and use the provided UseStudent.java to test your compareTo() method.

Part 2 [Note: Save your successful implementation of Part 1. We are about to extend it!] So the feedback you get from the President is “This is fantastic! But hey, can you folks produce 2 other sorts that list Students first by Gpa within projected graduation year (classof) and a second one that produces a list by Major within projected graduation year? So your skillful implementation has produced a complement along with some more work for you (This is the real world, folks!) So now you have to strategize on how to do this. The solution that is thought to be best involves creating a field within Student that indicates how it should be ordered. This has a slight drawback but if we want to keep compareTo() compatible with all sort routines that might use it, we have to make a few sacrifices. We can't add a parameter to compareTo() so we embed the info in the Student class itself. In Student.java near the top of the class, add the following public constants: public final static int order_Gpa_Within_Major = 1; public final static int order_Gpa Within ClassOf = 2; public final static int order_Major_Within_ClassOf = 3; Add a member called ordering which is an integer. Add a getter and setter for it. Also, add another type of getter that examines ordering and returns a string instead of just the integer value. Use the following strings: order_Gpa_Within_Major (1) - return "Gpa Within Major" order_Gpa_Within_ClassOf (2) - return "Gpa Within ClassOf" order_Major_Within_ClassOf (3) - return "Major Within ClassOf" The prototype for this function is: public String orderingString0; So now, compareTo() must examine ordering to discover which of 3 orderings to use. Based on that, it performs the test for the selected criteria and returns a negative value, 0 or a positive value. Note: You will probably want to add a Constructor which includes a parameter to set the ordering member. I recommend you keep the original constructor! The new constructor includes the new parameters. Modify the original Constructor to call the new Constructor and use a default value for ordering (i.e. add order_Gpa_Within_Major to the parameter list and call the new Constructor. Move all the assignments that set the other members to the new Constructor. This way, all of the member setting occurs in primarily 1 Constructor and the Constructors rely on each other so you do not duplicate a lot of code! The operation of the class now works as follows: 1. Make sure all Student records in an array have been set to use the same ordering with 2. Call the selection sort. 3. Iterate through and print the students. One added complication. As with the first sort, you want to sequence the printed fields so the sort criteria occurs up front. So toString() should be modified to look at the ordering and return a different string depending on the ordering member. Iterative Development! This is a great opportunity to work iteratively'. That is, develop a bit and test it. Then develop more and test the new code. Then 'integrate the various tested parts into a whole. So I recommend the following:

Copy your original Student.java Replace the compareTo() with new code that implements one of the new sorts Replace toString() to generate a string with the correct fields in the front of the text based on the new sort order. Test that code with the original UseStudent.java (basic) Once the second sort and toString work, Repeat the above writing a 3d compare T0 [comenting out the old compareTo() for now) to implement the third sort method. Correct the toString) code as well. Verify the 3rd sort works. Finally, you will now integrate your code into a single Student class. Add the constants given at the start of part 2. Add the member and its getters and setters. Modify your compareTo() code to base its comparisons on the setting in the ordering member. Assume that these will always be consistent between Student objects. Make toString() examine ordering and base its returned string on that value. Test your latest code with the UseStudent2.java file to test your implementation. This will assume interfaces exist the change ordering.

Part 3 [Optional - Extra Credit! 10 Points] If you made it through parts 1 and 2, consider the following: The design is a bit clunky. The user has to step through the array and make sure all objects have the same sort option selected. How about the following: Design a class called StudentBody and this class is a 'container' that will hold the Student array. The Constructor should simply take an array of Student records. It should have the prototype: public StudentBody (Student[] studentRecords); From that point, it will set the sort order to some default option (like order_Gpa_Within_Major ). Then, provide a method called setOrdering() that takes an integer representing the sort order. You can call this using the constants you created for the sort order (since they are just integers anyway). The prototype for the method is: public void setOrdering(int order); The setOrdering() method steps through the array and sets the ordering for each object in the array. This makes managing the array easier for the user. Also, implement a sort method which takes no argument but calls your sort method passing it the students in the array it is holding and returning void (nothing). Finally, implement a printStudents() method that takes no arguments and returns nothing but it prints out the objects in the Students array it holds.

This will make the user interface much easier to manage. Now they simply use a sequence like: StudentBody sb; // Create and populate an array of students here sb = new StudentBody(studentArray); sb.setOrdering(order_Gpa_Within_ClassOf); sb.sortO; sb.printStudents(); To test this, use the UseStudent3.java file to test your implementation.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply