Question: Goal : Practicing classes, interactive program Follow the template provided at https://github.com/pisanuw/css142/ to create a Student.java, University.java and Registrar.java. Pay attention to the comments. The
Goal : Practicing classes, interactive program
Follow the template provided at https://github.com/pisanuw/css142/ to create a Student.java, University.java and Registrar.java. Pay attention to the comments. The Readme.txt file has list of input commands that you can copy and paste to make it easier for testing.
You will have to play with the existing JAR file to get a sense of the interaction.
Student -- Each student has a name, list of registered courses kept in an array, and a variable numberOfRegisteredCourses showing how many courses they are currently registered in. The variable university is set to the University object that the student is enrolled in.
University -- University object keeps track of courses and students. Students enroll at the university, courses can be added to the list of courses.
Registrar -- Registrar provides the menu choices to create a new University object, add new courses and students to the university.
A typical interaction (as provided in Readme.txt) is as follows:
Welcome to the Registrar program Enter a name for University: UWB Welcome to the menu 1. Display information about the university 2. List all courses
3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 1 Choice is 1 UWB has 0 courses and 0 students
1
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 2 Choice is 2 Courses are:
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 3 Choice is 3 Enter a course name: 142 Added new course
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 1 Choice is 1 UWB has 1 courses and 0 students
Welcome to the menu 1. Display information about the university 2. List all courses
2
3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 2 Choice is 2 Courses are: 142
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 3 Choice is 3 Enter a course name: 142 Already have a course named 142
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 3 Choice is 3 Enter a course name: 132 Added new course
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course
3
4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 4 Choice is 4 Enter a student name: Kris Enrolled student
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 1 Choice is 1 UWB has 2 courses and 1 students
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 4 Choice is 4 Enter a student name: Jo Enrolled student
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students
4
6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 6 Choice is 6 Enter a student name: Johnny Could not find student with name Johnny
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 5 Choice is 5 Students are: Kris Jo
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 6 Choice is 6 Enter a student name: Kris Enter a course name: 142 Kris is now registered for 142 Registered student for a course
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student
5
5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 7 Choice is 7 Enter a course name: 132 Students in 132 are:
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 7 Choice is 7 Enter a course name: 200 200 is not one of the courses offered
Welcome to the menu 1. Display information about the university 2. List all courses 3. Add a course 4. Enroll a new student 5. List all students 6. Register a student for a course 7. List all students enrolled in a course 10. Exit Enter command: 10 Choice is 10 Thank you for using the Registrar program
If you complete all the requirements, you can attempt the bonus options. You will only get bonus points if the your base program is correct, so do not attempt the bonus part unless you have tested your program thoroughly..
Bonus +2 points - Implement a menu item to drop a course.
6
Bonus +5 points - Change the menu system, so you can work with multiple universities. You will need to make significant changes to the menu system.
Below is a copy of the 3 class templates
| /** |
| | * Write a description of class Registrar here. |
| | * |
| | * @author (your name) |
| | * @version (a version number or a date) |
| | */ |
| | |
| | import java.util.*; |
| | |
| | public class Registrar |
| | { |
| | // static variable, so we can use the same keyboard for all input |
| | static Scanner keyboard = new Scanner(System.in); |
| | |
| | // prompt user for integer and return it |
| | private static int getChoice(String prompt) |
| | { |
| | System.out.print(prompt); |
| | int choice = keyboard.nextInt(); |
| | return choice; |
| | } |
| | |
| | // prompt user for String and return it |
| | private static String getString(String prompt) |
| | { |
| | System.out.print(prompt); |
| | String str = keyboard.next(); |
| | return str; |
| | } |
| | |
| | // Main menu for program, asks university name |
| | // creates university object and calls universityMenu |
| | public static void mainMenu() |
| | { |
| | System.out.println("Welcome to the Registrar program"); |
| | String uniName = getString("Enter a name for University: "); |
| | University uni = new University(uniName); |
| | universityMenu(uni); |
| | } |
| | |
| | // Main university menu with registrar functions |
| | private static void universityMenu(University uni) |
| | { |
| | System.out.println("Welcome to the " + uni + " menu"); |
| | System.out.println("1. Display information about the university"); |
| | System.out.println("2. List all courses"); |
| | System.out.println("3. Add a course"); |
| | System.out.println("4. Enroll a new student"); |
| | System.out.println("5. List all students"); |
| | System.out.println("6. Register a student for a course"); |
| | System.out.println("7. List all students enrolled in a course"); |
| | System.out.println("10. Exit"); |
| | int choice = getChoice("Enter command: "); |
| | System.out.println("Choice is " + choice); |
| | switch (choice) |
| | { |
| | case 1: uni.information(); break; |
| | case 2: uni.listCourses(); break; |
| | case 3: addCourse(uni); break; |
| | case 4: enrollAStudent(uni); break; |
| | case 5: uni.listStudents(); break; |
| | case 6: registerStudentForCourse(uni); break; |
| | case 7: listStudentsInCourse(uni); break; |
| | case 10: |
| | System.out.println("Thank you for using the Registrar program"); |
| | System.exit(0); |
| | |
| | default: System.out.println("Invalid choice " + choice); |
| | } |
| | System.out.println(); |
| | universityMenu(uni); |
| | } |
| | |
| | // checks if the course is already offered at university |
| | // if course is not offered, adds course |
| | private static void addCourse(University uni) |
| | { |
| | // TODO |
| | System.out.println("Added new course"); |
| | } |
| | |
| | // gets name from user, creates Student object and |
| | // enrolls the new student at university |
| | private static void enrollAStudent(University uni) |
| | { |
| | // TODO |
| | System.out.println("Enrolled student"); |
| | } |
| | |
| | // gets name from user, checks if the student with that name |
| | // can be found at university. |
| | // If student is found, gets course name |
| | // if course is offered at university and student is not |
| | // already registered for the course, add student to that course |
| | private static void registerStudentForCourse(University uni) |
| | { |
| | // TODO |
| | System.out.println("Registered student for a course"); |
| | } |
| | |
| | // gets course name from user, if course is offered |
| | // prints all students taking that course |
| | private static void listStudentsInCourse(University uni) |
| | { |
| | // TODO |
| | } |
| | |
| | // calls mainMenu - useful when running from command line outside of BlueJ |
| | public static void main(String[] args) |
| | { |
| | mainMenu(); |
| | } |
| | } | /** | | | * Write a description of class Student here. | | | * | | | * @author (your name) | | | * @version (a version number or a date) | | | */ | | | public class Student | | | { | | | private static int MAX_REGISTERED_COURSES = 4; // max number of courses a student can enroll | | | | | | private String name; // name of student | | | private String registeredCourses[]; // list of currently registered courses | | | private int numberOfRegisteredCourses; // number of courses currently registered | | | private University university; // university student belongs to | | | | | | // constructor -- create a new student at this university | | | public Student(String newName, University uni) | | | { | | | // TODO | | | } | | | | | | // return the name of student | | | // name is a private variable, so need getter method | | | public String getName() | | | { | | | return name; | | | } | | | | | | // return true if student is registered for the given course | | | public boolean isRegisteredFor(String courseName) | | | { | | | // TODO | | | return false; | | | } | | | | | | // add the course to the list of registeredCourses | | | // Display message if University does not foffer this course | | | // Display message if student already registered for this course | | | public void add(String courseName) | | | { | | | | | | // TODO | | | System.out.println(name + " is now registered for " + courseName); | | | } | | | | | | // list all courses that student is registered for | | | private void listCourses() | | | { | | | // TODO | | | } | | | | | | public void drop(String courseName) | | | { | | | // HARD | | | // Bonus question | | | } | | | | | | } | /** | | | * Write a description of class University here. | | | * | | | * @author (your name) | | | * @version (a version number or a date) | | | */ | | | public class University | | | { | | | private static int MAX_COURSES = 100; // max courses at university | | | private static int MAX_STUDENTS = 1000; // max students at university | | | | | | private String courses[]; // courses currently offered | | | private int numberOfCourses; // number of courses currently on offer | | | private Student students[]; // students enrolled at university | | | private int numberOfStudents; // number of students currently enrolled | | | private String name; // name of university | | | | | | // constructor -- set name of university | | | // initialize courses array, | | | // initialize students array | | | // initialize numberOfCourses, numberOfStudents | | | public University(String newName) | | | { | | | // TODO | | | } | | | | | | // return true if a course with the given name is offered | | | public boolean hasCourse(String courseName) | | | { | | | // TODO | | | return false; | | | } | | | | | | // print out all courses offered | | | public void listCourses() | | | { | | | System.out.println("Courses are: "); | | | // TODO | | | } | | | | | | // add a new course to courses[] | | | public void addCourse(String courseName) | | | { | | | // TODO | | | } | | | | | | // print out all students enrolled at university | | | public void listStudents() | | | { | | | System.out.println("Students are:"); | | | // TODO | | | } | | | | | | // print out all students enrolled in htis course | | | public void listStudentsInCourse(String courseName) | | | { | | | System.out.println("Students in " + courseName + " are:"); | | | // TODO | | | } | | | | | | // return a Student object based on name | | | // if no student with that name found, return null | | | public Student getStudent(String name) | | | { | | | // TODO | | | return null; | | | } | | | | | | // enroll a student at university | | | public void enroll(Student student) | | | { | | | // TODO | | | } | | | | | | // display information about university | | | public void information() | | | { | | | System.out.println(name + " has " + numberOfCourses + " courses and " + numberOfStudents + " students"); | | | } | | | | | | // short string when university object is printed | | | public String toString() | | | { | | | return "<" + name + ">"; | | | } | | | | | | } | | |