Imagine that you were required to write a Java program which will store, manipulate, and print student registration information.
As part of the solution, identify the following classes:
(a) Student
(b) Admissions.
The class Student has the following fields – Name, Address, Id number, Courses, and Date, where:
(a) Name is a user defined class comprising of at minimum first name and last name.
(b) Address is a user defined class comprising of fields - street, city, state, and zip code.
(c) Date is a predefined class in the java.util package
(d) Id number uniquely identifies a student.
(e) Courses is a user defined class that can store at most five courses for which a student may register for. A student after registering should be able to add/drop course(s).
The class Admissions stores and manipulates the student information (student record). Because the list of students may grow dynamically, it is best to use a dynamic data structure such as the ArrayList to store the information. This class should do the following, among other possible activities:
(a) Add student to the list
(b) Remove student from the list.
You are to provide a test class that coordinates the activities of the classes outlined above, by:
• Creating student objects and adding them to the database of the Admissions object
• Removing a student from the database
• Change a student’s last name
• Displaying list of currently registered students
• Displaying list of all students that were dropped from the course
The output must be formatted as follows, and must be placed in a scrollable pane:
CURRENTLY ENROLLED
Id number: 123456
Name: Williams, John
Address: 2525 Hartsfield Road
Tallahassee, FL 33319
Date: September 5, 2010
Courses: COP3337 MAC2311 ENC1102 :
:
:
STUDENT WHO WERE DROPPED
Id number: 56789-0
Name: Roberts, Kay-Anne
Date: September 5, 2010
Code:
import java.util.ArrayList; public class Admissions { ArrayList <Student>list; // The list // Required for searching int index; // Position where record was found boolean found; // Whether or not record was found Student student;// Whose record was found Admissions() { list = new ArrayList<>(); } void add(Student o) { // Complete method } boolean empty() { // Complete method } int size() { return list.size(); } Student remove(int i) { // Complete method } ArrayList getList() { return list; } int getIndex() { // Complete method } Student getStudent() { return student; } boolean inList() { // Complete method } void search (String id) // Search list depending on the id { found = false; // Determines if item in list index = 0; // Required for index int length = list.size(); while ( index < length && !found) // Yet others may prefer th for loop { student = list.get(index); if (student.getId().compareTo(id) == 0) found = true; else index++; } } }
admissions Class
import java.util.ArrayList; public class Courses { static final int MAX_COURSES = 5; ArrayList <String> crses; public Courses() { crses = new ArrayList<String>(); } boolean add(String s) { if (crses.size() >= MAX_COURSES) return false; crses.add(s); return true; } boolean drop(String crse) { // Complete method } ArrayList getCourses() { return crses; } }
test class:
import java.util.ArrayList; import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.JScrollPane; class StudentAdmissions { public static void main(String arg[]) { Admissions db = new Admissions(); String menu = "1. Add student\n2. Add courses\n3. Drop course\n4. Drop student\n5. Display\n6. Modify name\n7. Exit"; boolean more = true; while(more) { int i = GetData.getInt(menu); switch(i) { case 1: // Register new student // Create name object String first = GetData.getWord("Enter first name"); String last = GetData.getWord("Enter last name"); Name n = new Name(first, last); // Create address object String street = GetData.getWord("Enter street"); String city = GetData.getWord("Enter city"); String state = GetData.getWord("Enter state"); String zip = GetData.getWord("Enter zip"); Address addr = new Address(street, city, state, zip); // Get student id String id = GetData.getWord("Enter id number"); // Create Course object Courses crse = new Courses(); int option = GetData.getInt("Ready to add courses?\n1. Yes\n2. No"); if(option == 1) addCourse(crse); // Create student object Student s = new Student(n, addr, id, crse); // Add student object to the database db.add(s); break; case 2: //Existing student int enter = GetData.getInt("Want to add course?\n1. Yes\n2. No"); break; case 3: // Existing student int drop = GetData.getInt("Want to drop a course?\n1. Yes\n2. No"); break; case 4: // Existing student int drp = GetData.getInt("Want to drop a student?\n1. Yes\n2. No"); break; case 5: // Display information - current OR dropped int displ = GetData.getInt("Show\n1. Current student\n2. Dropped students"); break; case 6: // Modify student's record break; case 7: // End process more = false; break; default: // Do nothing break; } } } static void addCourse(Courses crse) { boolean addAnotherCourse = true; while(addAnotherCourse) { int enter = GetData.getInt("Do you want to add course?\n1. Yes\n2. No"); switch(enter) { case 1: String course = GetData.getWord("Enter name of course"); if (!(crse.add(course))) { display("Can't add any more course", "Cousre Limit Reached", JOptionPane.WARNING_MESSAGE); addAnotherCourse = false; } break; case 2: addAnotherCourse = false; break; default: break; } } } static void display(String msg, String title, int type) { JOptionPane.showMessageDialog(null, msg,title, type ); } }
--- Update ---
need help completing the methods