The sections after this explain the methods you are to write, how to access the project...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
The sections after this explain the methods you are to write, how to access the project starting code, submit your code, etc. This project involves writing some methods to simulate the registration system for a small university. The registration system has to keep track of different courses being offered, as well as the students who are registered for each course. Courses can be taught in different departments, and each course has a seat count, or a maximum number of students who can be enrolled in it. The problem isn't that interesting, but it does involve using basic concepts from CMSC 131, such as the ArrayList class, and objects that contain and use other objects. The starting code that you will check out from your CVS repository contains a Registrar class that you will use to implement your simulation of the registration system. You can add whatever fields and write whatever methods you need in the Registrar class- given the constraints in Section 6.1- that will allow you to write the required methods described here. You may also add any other classes to the project, but they must be located in the registrar package (or the tests package, but only classes related to your student tests described below should be put there). Note that one constraint in Section 6.1 is that you must use an ArrayList in at least one place for storing data in your program. It can be directly in the Registrar class, or it can be in some other class that you add, as long as it's storing some part of the necessary data. 3.1 Registrar addNewCourse (String department, int number, int numSeats) This method should add a course to its current object Registrar. Its parameters represent the department of the course being added (e.g., "CMSC", "ENGL", etc.), the number of the course being added, and its seat count or enrollment limit. Due to the assumptions above, the method may assume without having to check these things that department is neither null nor an empty string. The method should return a reference to its current object, to allow chained calls, for example, a call like registrar.addNewCourse("CMSC", 132, 534).anotherMethod(), where anotherMethod () might be one of the methods described below (or even another call to addNewCourse()). If there is already a course in the current object Registrar that has the same number and is being taught in the same department, the method should not have any effect (should not add anything), and should just return a reference to the unmodified current object. The course should also not be added if number is zero or negative, or if numSeats is zero or negative. Otherwise the method should add a course with the department, number, and seat count indicated by its parameters to the current object, and return a reference to the modified current object. There is no limit to the number of courses that can be added to a university, so your method should be able to be called any number of times on the same Registrar object. No two courses in the same department can have the same number, but courses in different departments can have the same number, and there can be different courses in the same department, as long as they have different numbers. Note that your code should allow multiple Registrar objects to be created and manipulated simultaneously (each one representing a different university's registration system), and their data should not conflict. Each Registrar registration system object stores its own courses, and adding a course to one university registration system has no effect on the courses at any other university. The way that courses are stored in a Registrar object is up to you, subject to the constraints in Section 6.1, so be sure to read that section carefully. 3.2 boolean cancel Course (String department, int number) This method should remove the course with number number being taught in department department from its current object Registrar, which would be done if the course is canceled for any reason. As described below, courses can have students enrolled in them-after a course is canceled, all of the students it had are not registered for it any longer. The method should return true after removing the course, but if the current object does not have a course in the department department with number number it should not modify anything, and just return false instead. When this method is called the university registration system may have other courses in the same department with different numbers, or other courses in different departments with the same number, but those will not be affected. Only the course number in department department (if it exists) will be removed. If a course is canceled, another course with that same number in the same department could be re-added to the same Registrar object later. 3.3 int numCourses () This method should return the number of courses that currently exist in (have been added to) its current object Registrar, which should always be a nonnegative number. 3.4 boolean addToCourse (String department, int number, String firstName, String lastName) This method should add a student to the course with number number being taught in the department department in the current object Registrar. The last two parameters are the first and last names of the student to add. If a student with first name firstName and last name lastName can be added to the indicated course in the current object, the method should add the student and return true. There are several cases in which a student cannot be added, however: A university that your code is simulating the registration system of is just a small school, which does not have any students with identical names enrolled. So if addToCourse () is ever called when the course number in department department already has a student whose first name is firstName and whose last name is lastName, the method should not have any effect, and should just return false because it means that the same student is already enrolled for the course, and a student cannot take the same course twice. ⚫ The method should also return false without changing anything if the current object Registrar is not currently storing a course with number number in department department. The university that will use your code also does not allow students to register for more than five courses, so the method must return false without changing anything if the student with first name firstName and last name lastName has already added five other courses (regardless of what department or departments they are in). Lastly, no course can have more students in it than the number of seats that the course was created with when it was added to the registration system, indicated by the value of the third parameter to addNewCourse(). If course number number in department department is already full, meaning that it already has that many students who added, the method should also return false without changing anything. Suggestion: as you can see, there are various situations or special cases in which the method should not add the student to the course. It might be easiest to just write the method for the normal situation first, meaning get it to work assuming that the add will always succeed. You might even write the rest of the methods below next, because some of them might be useful in getting the functionality of the special cases to work. Then go back and add code to this method to handle the special cases above. 3.5 int numStudents InCourse (String department, int number) This method should return the number of students currently in course number number in department department stored in its current object Registrar. A course that is present in a Registrar should always have a nonnegative number of students, but if the current object does not have a course with number number in department department the method should return -1 instead. 3.6 int numStudents InCourseWithLast Name (String department, int number, String lastName) For some reason not explained here a university may want to know how many students in a course have the same last names, even if their first names are different. This method should return the number of students currently in course number number in department department stored in its current object Registrar who have last name lastName, regardless of their first name. The result will be zero or more unless there is no course with number number in department department currently being stored in the current object, in which case -1 should be returned instead. 3.7 boolean is InCourse (String department, int number, String firstName, String lastName) This method should return true if there is a student with first name firstName and last name lastName who is currently registered in course number number in department department stored in its current object. It should return false if there is no course with number number in department department currently being stored, or if there is such a course but there is no student with both of those names currently registered for it. 3.8 int howManyCourses Taking (String firstName, String lastName) This method should return the number of courses that the student with first name firstName and last name lastName is currently registered for in the current object Registrar. Due to the behavior of the addToCourse () method above this should always be a number between 0 and 5 (inclusive). If there is no student with first name firstName and last name lastName in any courses in the university the method should just return 0. 3.9 boolean dropCourse (String department, int number, String firstName, String lastName) This method should remove or drop the student with first name first Name and last name last Name from course number number being taught in department department that is stored in the current object Registrar. If the current object Registrar does not currently have a course with that number in that department, or if there is a course with that number in that department but it doesn't have a student in it who has both of those names, the method should not modify anything and just return false. Otherwise it should remove the student from the course and return true. Due to the behavior of the addToCourse () method described above, there should never be two or more students who have both the same first name and same last name in any course in a Registrar object, so this method will only remove (at most) one student. Removing a student from one course does not affect other students who are also in that course, and it also doesn't remove that student from any other courses that they are registered for. If course number in department department is currently full and this method is called to drop a student from it, it opens up a space so another student can subsequently be added. And if the student with first name firstName and last name last Name is currently registered for five courses, meaning that they would not be able to add a sixth (due to the behavior of the addToCourse () method described above), and this method is called to drop the student from one of their courses, they would be able to add some other course after that (or even re-add the same course later). 3.10 boolean cancelRegistration (String firstName, String lastName) This method should remove or drop the student with first name firstName and last name lastName from all of the courses that they are currently taking in the current object Registrar. If a student with both of these names is in the university registration system when the method is called, meaning they are currently registered for at least one course, the method should remove them from all of their courses and return true. If there is no student with both of those names in any courses in the university when the method is called, the method should not modify anything and just return false. If a student cancels their registration they can still re-enroll in courses later (just by calling addToCourse () with their first and last names). And if a student cancels their registration, it opens up space in all of the courses that they had previously been registered for. 4 Department and student names, and comparing names You may assume, without having to check, that department names will not contain spaces. Student first and last names may have spaces though. Some people have a multi-word last name such as "Baron Cohen", or first name such as "Mary Kate". Names can have punctuation, such as Pinkett-Smith or O'Brien, or even Ke$ha. At some points courses will have to be looked up or searched for using their department name (and course number), and students will need to be looked up using their first and last names. In any such comparisons case and spacing are significant the parameter must match department and student names exactly, including capitalization. For example, if a student has first name "Sally" and last name "Student" then they would not be the same student as one with first name "sally" or first name "SALLY", even if the other student's last name was "Student". Some methods need to see if their parameters contain the same value as a department name or a student first or last name, but the parameter does not have to be the exact same object as a department or student name. Two separate objects, like Strings or Integers, can have the same values. If so, they should compare as equal. You must use methods that compare whether department or student names have the same value, rather than using reference comparison. The sections after this explain the methods you are to write, how to access the project starting code, submit your code, etc. This project involves writing some methods to simulate the registration system for a small university. The registration system has to keep track of different courses being offered, as well as the students who are registered for each course. Courses can be taught in different departments, and each course has a seat count, or a maximum number of students who can be enrolled in it. The problem isn't that interesting, but it does involve using basic concepts from CMSC 131, such as the ArrayList class, and objects that contain and use other objects. The starting code that you will check out from your CVS repository contains a Registrar class that you will use to implement your simulation of the registration system. You can add whatever fields and write whatever methods you need in the Registrar class- given the constraints in Section 6.1- that will allow you to write the required methods described here. You may also add any other classes to the project, but they must be located in the registrar package (or the tests package, but only classes related to your student tests described below should be put there). Note that one constraint in Section 6.1 is that you must use an ArrayList in at least one place for storing data in your program. It can be directly in the Registrar class, or it can be in some other class that you add, as long as it's storing some part of the necessary data. 3.1 Registrar addNewCourse (String department, int number, int numSeats) This method should add a course to its current object Registrar. Its parameters represent the department of the course being added (e.g., "CMSC", "ENGL", etc.), the number of the course being added, and its seat count or enrollment limit. Due to the assumptions above, the method may assume without having to check these things that department is neither null nor an empty string. The method should return a reference to its current object, to allow chained calls, for example, a call like registrar.addNewCourse("CMSC", 132, 534).anotherMethod(), where anotherMethod () might be one of the methods described below (or even another call to addNewCourse()). If there is already a course in the current object Registrar that has the same number and is being taught in the same department, the method should not have any effect (should not add anything), and should just return a reference to the unmodified current object. The course should also not be added if number is zero or negative, or if numSeats is zero or negative. Otherwise the method should add a course with the department, number, and seat count indicated by its parameters to the current object, and return a reference to the modified current object. There is no limit to the number of courses that can be added to a university, so your method should be able to be called any number of times on the same Registrar object. No two courses in the same department can have the same number, but courses in different departments can have the same number, and there can be different courses in the same department, as long as they have different numbers. Note that your code should allow multiple Registrar objects to be created and manipulated simultaneously (each one representing a different university's registration system), and their data should not conflict. Each Registrar registration system object stores its own courses, and adding a course to one university registration system has no effect on the courses at any other university. The way that courses are stored in a Registrar object is up to you, subject to the constraints in Section 6.1, so be sure to read that section carefully. 3.2 boolean cancel Course (String department, int number) This method should remove the course with number number being taught in department department from its current object Registrar, which would be done if the course is canceled for any reason. As described below, courses can have students enrolled in them-after a course is canceled, all of the students it had are not registered for it any longer. The method should return true after removing the course, but if the current object does not have a course in the department department with number number it should not modify anything, and just return false instead. When this method is called the university registration system may have other courses in the same department with different numbers, or other courses in different departments with the same number, but those will not be affected. Only the course number in department department (if it exists) will be removed. If a course is canceled, another course with that same number in the same department could be re-added to the same Registrar object later. 3.3 int numCourses () This method should return the number of courses that currently exist in (have been added to) its current object Registrar, which should always be a nonnegative number. 3.4 boolean addToCourse (String department, int number, String firstName, String lastName) This method should add a student to the course with number number being taught in the department department in the current object Registrar. The last two parameters are the first and last names of the student to add. If a student with first name firstName and last name lastName can be added to the indicated course in the current object, the method should add the student and return true. There are several cases in which a student cannot be added, however: A university that your code is simulating the registration system of is just a small school, which does not have any students with identical names enrolled. So if addToCourse () is ever called when the course number in department department already has a student whose first name is firstName and whose last name is lastName, the method should not have any effect, and should just return false because it means that the same student is already enrolled for the course, and a student cannot take the same course twice. ⚫ The method should also return false without changing anything if the current object Registrar is not currently storing a course with number number in department department. The university that will use your code also does not allow students to register for more than five courses, so the method must return false without changing anything if the student with first name firstName and last name lastName has already added five other courses (regardless of what department or departments they are in). Lastly, no course can have more students in it than the number of seats that the course was created with when it was added to the registration system, indicated by the value of the third parameter to addNewCourse(). If course number number in department department is already full, meaning that it already has that many students who added, the method should also return false without changing anything. Suggestion: as you can see, there are various situations or special cases in which the method should not add the student to the course. It might be easiest to just write the method for the normal situation first, meaning get it to work assuming that the add will always succeed. You might even write the rest of the methods below next, because some of them might be useful in getting the functionality of the special cases to work. Then go back and add code to this method to handle the special cases above. 3.5 int numStudents InCourse (String department, int number) This method should return the number of students currently in course number number in department department stored in its current object Registrar. A course that is present in a Registrar should always have a nonnegative number of students, but if the current object does not have a course with number number in department department the method should return -1 instead. 3.6 int numStudents InCourseWithLast Name (String department, int number, String lastName) For some reason not explained here a university may want to know how many students in a course have the same last names, even if their first names are different. This method should return the number of students currently in course number number in department department stored in its current object Registrar who have last name lastName, regardless of their first name. The result will be zero or more unless there is no course with number number in department department currently being stored in the current object, in which case -1 should be returned instead. 3.7 boolean is InCourse (String department, int number, String firstName, String lastName) This method should return true if there is a student with first name firstName and last name lastName who is currently registered in course number number in department department stored in its current object. It should return false if there is no course with number number in department department currently being stored, or if there is such a course but there is no student with both of those names currently registered for it. 3.8 int howManyCourses Taking (String firstName, String lastName) This method should return the number of courses that the student with first name firstName and last name lastName is currently registered for in the current object Registrar. Due to the behavior of the addToCourse () method above this should always be a number between 0 and 5 (inclusive). If there is no student with first name firstName and last name lastName in any courses in the university the method should just return 0. 3.9 boolean dropCourse (String department, int number, String firstName, String lastName) This method should remove or drop the student with first name first Name and last name last Name from course number number being taught in department department that is stored in the current object Registrar. If the current object Registrar does not currently have a course with that number in that department, or if there is a course with that number in that department but it doesn't have a student in it who has both of those names, the method should not modify anything and just return false. Otherwise it should remove the student from the course and return true. Due to the behavior of the addToCourse () method described above, there should never be two or more students who have both the same first name and same last name in any course in a Registrar object, so this method will only remove (at most) one student. Removing a student from one course does not affect other students who are also in that course, and it also doesn't remove that student from any other courses that they are registered for. If course number in department department is currently full and this method is called to drop a student from it, it opens up a space so another student can subsequently be added. And if the student with first name firstName and last name last Name is currently registered for five courses, meaning that they would not be able to add a sixth (due to the behavior of the addToCourse () method described above), and this method is called to drop the student from one of their courses, they would be able to add some other course after that (or even re-add the same course later). 3.10 boolean cancelRegistration (String firstName, String lastName) This method should remove or drop the student with first name firstName and last name lastName from all of the courses that they are currently taking in the current object Registrar. If a student with both of these names is in the university registration system when the method is called, meaning they are currently registered for at least one course, the method should remove them from all of their courses and return true. If there is no student with both of those names in any courses in the university when the method is called, the method should not modify anything and just return false. If a student cancels their registration they can still re-enroll in courses later (just by calling addToCourse () with their first and last names). And if a student cancels their registration, it opens up space in all of the courses that they had previously been registered for. 4 Department and student names, and comparing names You may assume, without having to check, that department names will not contain spaces. Student first and last names may have spaces though. Some people have a multi-word last name such as "Baron Cohen", or first name such as "Mary Kate". Names can have punctuation, such as Pinkett-Smith or O'Brien, or even Ke$ha. At some points courses will have to be looked up or searched for using their department name (and course number), and students will need to be looked up using their first and last names. In any such comparisons case and spacing are significant the parameter must match department and student names exactly, including capitalization. For example, if a student has first name "Sally" and last name "Student" then they would not be the same student as one with first name "sally" or first name "SALLY", even if the other student's last name was "Student". Some methods need to see if their parameters contain the same value as a department name or a student first or last name, but the parameter does not have to be the exact same object as a department or student name. Two separate objects, like Strings or Integers, can have the same values. If so, they should compare as equal. You must use methods that compare whether department or student names have the same value, rather than using reference comparison. The sections after this explain the methods you are to write, how to access the project starting code, submit your code, etc. This project involves writing some methods to simulate the registration system for a small university. The registration system has to keep track of different courses being offered, as well as the students who are registered for each course. Courses can be taught in different departments, and each course has a seat count, or a maximum number of students who can be enrolled in it. The problem isn't that interesting, but it does involve using basic concepts from CMSC 131, such as the ArrayList class, and objects that contain and use other objects. The starting code that you will check out from your CVS repository contains a Registrar class that you will use to implement your simulation of the registration system. You can add whatever fields and write whatever methods you need in the Registrar class- given the constraints in Section 6.1- that will allow you to write the required methods described here. You may also add any other classes to the project, but they must be located in the registrar package (or the tests package, but only classes related to your student tests described below should be put there). Note that one constraint in Section 6.1 is that you must use an ArrayList in at least one place for storing data in your program. It can be directly in the Registrar class, or it can be in some other class that you add, as long as it's storing some part of the necessary data. 3.1 Registrar addNewCourse (String department, int number, int numSeats) This method should add a course to its current object Registrar. Its parameters represent the department of the course being added (e.g., "CMSC", "ENGL", etc.), the number of the course being added, and its seat count or enrollment limit. Due to the assumptions above, the method may assume without having to check these things that department is neither null nor an empty string. The method should return a reference to its current object, to allow chained calls, for example, a call like registrar.addNewCourse("CMSC", 132, 534).anotherMethod(), where anotherMethod () might be one of the methods described below (or even another call to addNewCourse()). If there is already a course in the current object Registrar that has the same number and is being taught in the same department, the method should not have any effect (should not add anything), and should just return a reference to the unmodified current object. The course should also not be added if number is zero or negative, or if numSeats is zero or negative. Otherwise the method should add a course with the department, number, and seat count indicated by its parameters to the current object, and return a reference to the modified current object. There is no limit to the number of courses that can be added to a university, so your method should be able to be called any number of times on the same Registrar object. No two courses in the same department can have the same number, but courses in different departments can have the same number, and there can be different courses in the same department, as long as they have different numbers. Note that your code should allow multiple Registrar objects to be created and manipulated simultaneously (each one representing a different university's registration system), and their data should not conflict. Each Registrar registration system object stores its own courses, and adding a course to one university registration system has no effect on the courses at any other university. The way that courses are stored in a Registrar object is up to you, subject to the constraints in Section 6.1, so be sure to read that section carefully. 3.2 boolean cancel Course (String department, int number) This method should remove the course with number number being taught in department department from its current object Registrar, which would be done if the course is canceled for any reason. As described below, courses can have students enrolled in them-after a course is canceled, all of the students it had are not registered for it any longer. The method should return true after removing the course, but if the current object does not have a course in the department department with number number it should not modify anything, and just return false instead. When this method is called the university registration system may have other courses in the same department with different numbers, or other courses in different departments with the same number, but those will not be affected. Only the course number in department department (if it exists) will be removed. If a course is canceled, another course with that same number in the same department could be re-added to the same Registrar object later. 3.3 int numCourses () This method should return the number of courses that currently exist in (have been added to) its current object Registrar, which should always be a nonnegative number. 3.4 boolean addToCourse (String department, int number, String firstName, String lastName) This method should add a student to the course with number number being taught in the department department in the current object Registrar. The last two parameters are the first and last names of the student to add. If a student with first name firstName and last name lastName can be added to the indicated course in the current object, the method should add the student and return true. There are several cases in which a student cannot be added, however: A university that your code is simulating the registration system of is just a small school, which does not have any students with identical names enrolled. So if addToCourse () is ever called when the course number in department department already has a student whose first name is firstName and whose last name is lastName, the method should not have any effect, and should just return false because it means that the same student is already enrolled for the course, and a student cannot take the same course twice. ⚫ The method should also return false without changing anything if the current object Registrar is not currently storing a course with number number in department department. The university that will use your code also does not allow students to register for more than five courses, so the method must return false without changing anything if the student with first name firstName and last name lastName has already added five other courses (regardless of what department or departments they are in). Lastly, no course can have more students in it than the number of seats that the course was created with when it was added to the registration system, indicated by the value of the third parameter to addNewCourse(). If course number number in department department is already full, meaning that it already has that many students who added, the method should also return false without changing anything. Suggestion: as you can see, there are various situations or special cases in which the method should not add the student to the course. It might be easiest to just write the method for the normal situation first, meaning get it to work assuming that the add will always succeed. You might even write the rest of the methods below next, because some of them might be useful in getting the functionality of the special cases to work. Then go back and add code to this method to handle the special cases above. 3.5 int numStudents InCourse (String department, int number) This method should return the number of students currently in course number number in department department stored in its current object Registrar. A course that is present in a Registrar should always have a nonnegative number of students, but if the current object does not have a course with number number in department department the method should return -1 instead. 3.6 int numStudents InCourseWithLast Name (String department, int number, String lastName) For some reason not explained here a university may want to know how many students in a course have the same last names, even if their first names are different. This method should return the number of students currently in course number number in department department stored in its current object Registrar who have last name lastName, regardless of their first name. The result will be zero or more unless there is no course with number number in department department currently being stored in the current object, in which case -1 should be returned instead. 3.7 boolean is InCourse (String department, int number, String firstName, String lastName) This method should return true if there is a student with first name firstName and last name lastName who is currently registered in course number number in department department stored in its current object. It should return false if there is no course with number number in department department currently being stored, or if there is such a course but there is no student with both of those names currently registered for it. 3.8 int howManyCourses Taking (String firstName, String lastName) This method should return the number of courses that the student with first name firstName and last name lastName is currently registered for in the current object Registrar. Due to the behavior of the addToCourse () method above this should always be a number between 0 and 5 (inclusive). If there is no student with first name firstName and last name lastName in any courses in the university the method should just return 0. 3.9 boolean dropCourse (String department, int number, String firstName, String lastName) This method should remove or drop the student with first name first Name and last name last Name from course number number being taught in department department that is stored in the current object Registrar. If the current object Registrar does not currently have a course with that number in that department, or if there is a course with that number in that department but it doesn't have a student in it who has both of those names, the method should not modify anything and just return false. Otherwise it should remove the student from the course and return true. Due to the behavior of the addToCourse () method described above, there should never be two or more students who have both the same first name and same last name in any course in a Registrar object, so this method will only remove (at most) one student. Removing a student from one course does not affect other students who are also in that course, and it also doesn't remove that student from any other courses that they are registered for. If course number in department department is currently full and this method is called to drop a student from it, it opens up a space so another student can subsequently be added. And if the student with first name firstName and last name last Name is currently registered for five courses, meaning that they would not be able to add a sixth (due to the behavior of the addToCourse () method described above), and this method is called to drop the student from one of their courses, they would be able to add some other course after that (or even re-add the same course later). 3.10 boolean cancelRegistration (String firstName, String lastName) This method should remove or drop the student with first name firstName and last name lastName from all of the courses that they are currently taking in the current object Registrar. If a student with both of these names is in the university registration system when the method is called, meaning they are currently registered for at least one course, the method should remove them from all of their courses and return true. If there is no student with both of those names in any courses in the university when the method is called, the method should not modify anything and just return false. If a student cancels their registration they can still re-enroll in courses later (just by calling addToCourse () with their first and last names). And if a student cancels their registration, it opens up space in all of the courses that they had previously been registered for. 4 Department and student names, and comparing names You may assume, without having to check, that department names will not contain spaces. Student first and last names may have spaces though. Some people have a multi-word last name such as "Baron Cohen", or first name such as "Mary Kate". Names can have punctuation, such as Pinkett-Smith or O'Brien, or even Ke$ha. At some points courses will have to be looked up or searched for using their department name (and course number), and students will need to be looked up using their first and last names. In any such comparisons case and spacing are significant the parameter must match department and student names exactly, including capitalization. For example, if a student has first name "Sally" and last name "Student" then they would not be the same student as one with first name "sally" or first name "SALLY", even if the other student's last name was "Student". Some methods need to see if their parameters contain the same value as a department name or a student first or last name, but the parameter does not have to be the exact same object as a department or student name. Two separate objects, like Strings or Integers, can have the same values. If so, they should compare as equal. You must use methods that compare whether department or student names have the same value, rather than using reference comparison. The sections after this explain the methods you are to write, how to access the project starting code, submit your code, etc. This project involves writing some methods to simulate the registration system for a small university. The registration system has to keep track of different courses being offered, as well as the students who are registered for each course. Courses can be taught in different departments, and each course has a seat count, or a maximum number of students who can be enrolled in it. The problem isn't that interesting, but it does involve using basic concepts from CMSC 131, such as the ArrayList class, and objects that contain and use other objects. The starting code that you will check out from your CVS repository contains a Registrar class that you will use to implement your simulation of the registration system. You can add whatever fields and write whatever methods you need in the Registrar class- given the constraints in Section 6.1- that will allow you to write the required methods described here. You may also add any other classes to the project, but they must be located in the registrar package (or the tests package, but only classes related to your student tests described below should be put there). Note that one constraint in Section 6.1 is that you must use an ArrayList in at least one place for storing data in your program. It can be directly in the Registrar class, or it can be in some other class that you add, as long as it's storing some part of the necessary data. 3.1 Registrar addNewCourse (String department, int number, int numSeats) This method should add a course to its current object Registrar. Its parameters represent the department of the course being added (e.g., "CMSC", "ENGL", etc.), the number of the course being added, and its seat count or enrollment limit. Due to the assumptions above, the method may assume without having to check these things that department is neither null nor an empty string. The method should return a reference to its current object, to allow chained calls, for example, a call like registrar.addNewCourse("CMSC", 132, 534).anotherMethod(), where anotherMethod () might be one of the methods described below (or even another call to addNewCourse()). If there is already a course in the current object Registrar that has the same number and is being taught in the same department, the method should not have any effect (should not add anything), and should just return a reference to the unmodified current object. The course should also not be added if number is zero or negative, or if numSeats is zero or negative. Otherwise the method should add a course with the department, number, and seat count indicated by its parameters to the current object, and return a reference to the modified current object. There is no limit to the number of courses that can be added to a university, so your method should be able to be called any number of times on the same Registrar object. No two courses in the same department can have the same number, but courses in different departments can have the same number, and there can be different courses in the same department, as long as they have different numbers. Note that your code should allow multiple Registrar objects to be created and manipulated simultaneously (each one representing a different university's registration system), and their data should not conflict. Each Registrar registration system object stores its own courses, and adding a course to one university registration system has no effect on the courses at any other university. The way that courses are stored in a Registrar object is up to you, subject to the constraints in Section 6.1, so be sure to read that section carefully. 3.2 boolean cancel Course (String department, int number) This method should remove the course with number number being taught in department department from its current object Registrar, which would be done if the course is canceled for any reason. As described below, courses can have students enrolled in them-after a course is canceled, all of the students it had are not registered for it any longer. The method should return true after removing the course, but if the current object does not have a course in the department department with number number it should not modify anything, and just return false instead. When this method is called the university registration system may have other courses in the same department with different numbers, or other courses in different departments with the same number, but those will not be affected. Only the course number in department department (if it exists) will be removed. If a course is canceled, another course with that same number in the same department could be re-added to the same Registrar object later. 3.3 int numCourses () This method should return the number of courses that currently exist in (have been added to) its current object Registrar, which should always be a nonnegative number. 3.4 boolean addToCourse (String department, int number, String firstName, String lastName) This method should add a student to the course with number number being taught in the department department in the current object Registrar. The last two parameters are the first and last names of the student to add. If a student with first name firstName and last name lastName can be added to the indicated course in the current object, the method should add the student and return true. There are several cases in which a student cannot be added, however: A university that your code is simulating the registration system of is just a small school, which does not have any students with identical names enrolled. So if addToCourse () is ever called when the course number in department department already has a student whose first name is firstName and whose last name is lastName, the method should not have any effect, and should just return false because it means that the same student is already enrolled for the course, and a student cannot take the same course twice. ⚫ The method should also return false without changing anything if the current object Registrar is not currently storing a course with number number in department department. The university that will use your code also does not allow students to register for more than five courses, so the method must return false without changing anything if the student with first name firstName and last name lastName has already added five other courses (regardless of what department or departments they are in). Lastly, no course can have more students in it than the number of seats that the course was created with when it was added to the registration system, indicated by the value of the third parameter to addNewCourse(). If course number number in department department is already full, meaning that it already has that many students who added, the method should also return false without changing anything. Suggestion: as you can see, there are various situations or special cases in which the method should not add the student to the course. It might be easiest to just write the method for the normal situation first, meaning get it to work assuming that the add will always succeed. You might even write the rest of the methods below next, because some of them might be useful in getting the functionality of the special cases to work. Then go back and add code to this method to handle the special cases above. 3.5 int numStudents InCourse (String department, int number) This method should return the number of students currently in course number number in department department stored in its current object Registrar. A course that is present in a Registrar should always have a nonnegative number of students, but if the current object does not have a course with number number in department department the method should return -1 instead. 3.6 int numStudents InCourseWithLast Name (String department, int number, String lastName) For some reason not explained here a university may want to know how many students in a course have the same last names, even if their first names are different. This method should return the number of students currently in course number number in department department stored in its current object Registrar who have last name lastName, regardless of their first name. The result will be zero or more unless there is no course with number number in department department currently being stored in the current object, in which case -1 should be returned instead. 3.7 boolean is InCourse (String department, int number, String firstName, String lastName) This method should return true if there is a student with first name firstName and last name lastName who is currently registered in course number number in department department stored in its current object. It should return false if there is no course with number number in department department currently being stored, or if there is such a course but there is no student with both of those names currently registered for it. 3.8 int howManyCourses Taking (String firstName, String lastName) This method should return the number of courses that the student with first name firstName and last name lastName is currently registered for in the current object Registrar. Due to the behavior of the addToCourse () method above this should always be a number between 0 and 5 (inclusive). If there is no student with first name firstName and last name lastName in any courses in the university the method should just return 0. 3.9 boolean dropCourse (String department, int number, String firstName, String lastName) This method should remove or drop the student with first name first Name and last name last Name from course number number being taught in department department that is stored in the current object Registrar. If the current object Registrar does not currently have a course with that number in that department, or if there is a course with that number in that department but it doesn't have a student in it who has both of those names, the method should not modify anything and just return false. Otherwise it should remove the student from the course and return true. Due to the behavior of the addToCourse () method described above, there should never be two or more students who have both the same first name and same last name in any course in a Registrar object, so this method will only remove (at most) one student. Removing a student from one course does not affect other students who are also in that course, and it also doesn't remove that student from any other courses that they are registered for. If course number in department department is currently full and this method is called to drop a student from it, it opens up a space so another student can subsequently be added. And if the student with first name firstName and last name last Name is currently registered for five courses, meaning that they would not be able to add a sixth (due to the behavior of the addToCourse () method described above), and this method is called to drop the student from one of their courses, they would be able to add some other course after that (or even re-add the same course later). 3.10 boolean cancelRegistration (String firstName, String lastName) This method should remove or drop the student with first name firstName and last name lastName from all of the courses that they are currently taking in the current object Registrar. If a student with both of these names is in the university registration system when the method is called, meaning they are currently registered for at least one course, the method should remove them from all of their courses and return true. If there is no student with both of those names in any courses in the university when the method is called, the method should not modify anything and just return false. If a student cancels their registration they can still re-enroll in courses later (just by calling addToCourse () with their first and last names). And if a student cancels their registration, it opens up space in all of the courses that they had previously been registered for. 4 Department and student names, and comparing names You may assume, without having to check, that department names will not contain spaces. Student first and last names may have spaces though. Some people have a multi-word last name such as "Baron Cohen", or first name such as "Mary Kate". Names can have punctuation, such as Pinkett-Smith or O'Brien, or even Ke$ha. At some points courses will have to be looked up or searched for using their department name (and course number), and students will need to be looked up using their first and last names. In any such comparisons case and spacing are significant the parameter must match department and student names exactly, including capitalization. For example, if a student has first name "Sally" and last name "Student" then they would not be the same student as one with first name "sally" or first name "SALLY", even if the other student's last name was "Student". Some methods need to see if their parameters contain the same value as a department name or a student first or last name, but the parameter does not have to be the exact same object as a department or student name. Two separate objects, like Strings or Integers, can have the same values. If so, they should compare as equal. You must use methods that compare whether department or student names have the same value, rather than using reference comparison.
Expert Answer:
Answer rating: 100% (QA)
This implementation uses a Map to store courses and another Map to store enrolled students The keys for the enrolled students map are generated by com... View the full answer
Related Book For
Introduction to Operations Research
ISBN: 978-1259162985
10th edition
Authors: Frederick S. Hillier, Gerald J. Lieberman
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
4. Papo and Pepe are two barbers from a small barbershop. Theyhave their two court chairs plus two waiting chairs. The followingresults were found: P0 = 1/16 P1 = 4/16 P2 = 6/16 P3 = 4/16 a. What is...
-
Wayne Mueller, financial analyst at CELL Corporation, is examining the behavior of quarterly utility costs for budgeting purposes. Mueller collects the following data on machine-hours worked and...
-
Determine the convergence or divergence of the series using any appropriate test from this chapter. Identify the test used. n=1 4 n2
-
A project has been selected for implementation. The net cash flow (NCF) profile associated with the project is shown below. MARR is 10 percent/year. a. What is the internal rate of return of this...
-
Wet sugar that contains one-fifth water by mass is conveyed through an evaporator in which 85.0% of the entering water is vaporized. (a) Taking a basis of 100 kg feed, calculate (i) XW, the mass...
-
3. You have been provided with the information listed below for the City of XYZ. 2024 2025 market value of taxable property $1.3 billion increases by 2.0% from 2024 exemptions $26 million increases...
-
Preparing an Individuals Tax Form. Caleb Lee graduated from college in 2018 and began work as a systems analyst in July of that year. He is preparing to file his income tax return for 2018, and has...
-
Problem 5: Find the velocity with which a particle must be projected along the interior of a smooth vertical hoop of radius a from the lowest point in order that it may leave the hoop at an angular...
-
The capital structure of a publicly traded company contains a single debt issue with the following characteristics: Fixed coupon-paying bond issue (semiannual pay) Par value: $80 million Coupon rate:...
-
A regulatory specialist may be tasked with presenting regulatory information on provider and patient rights in a way that all department employees and patients will understand the importance of...
-
The graph to the right depicts an economy, Home, which produces flowers and soybeans. Its production possibilities frontier is shown as TT. One of Home's isovalue lines is also shown as VV. Home...
-
Required: Calculate the covariance Invest 50% of your money in Asset A and 50% in B State of the economy Boom Bust Probability A return B return 0,4 20% 15% 0,6 -10% 9%
-
Being able to identify, create, and mess up arguments teaches so many useful lessons in thinking that we're going to give it the time it needs. Please answer the following questions fully and...
-
4..In the absorption coefficient experiment What happen if the thickness of materials decrease? (a)Nothing happens (b)The absorption increases (c)The absorption decreases (d)The absorption increases...
-
Prove the following D,(cos x) = - sin x (Hint: Apply the identity cos(A + B) = cos A cos B sin A sin B)
-
Consider the three-variable linear programming problem shown in Fig. 5.2. (a) Explain in geometric terms why the set of solutions satisfying any individual constraint is a convex set, as defined in...
-
Consider the expressions in matrix notation given in Sec. 13.7 for the general form of the KKT conditions for the quadratic programming problem. Show that the problem of finding a feasible solution...
-
Suppose F is IFR, with = 0.5. Find upper and lower bounds on R(t) for (a)t = 1/4 and (b) t = 1.
-
Orvil Companys net profit margin percentage is 4.5%, its total asset turnover is 2.4, and its equity multiplier is 1.5. What is the companys return on equity? a. 2.8% b. 7.2% c. 16.2% d. 10.7%
-
Obtain the most recent annual report or SEC filing 10-K of a publicly traded company that interests you. It may be a local company or it may be a company in an industry that you would like to know...
-
Endless Mountain Company manufactures a single product that is popular with outdoor recreation enthusiasts. The company sells its product to retailers throughout the northeastern quadrant of the...
Study smarter with the SolutionInn App