Part I: (15 pts) Create a Student class with the following: A private String var
ID: 3634140 • Letter: P
Question
Part I: (15 pts) Create a Student class with the following:A private String variable named “name” to store the student’s name
A private integer variable named “UFID” that contains the unique ID number for this student
A private String variable named “DOB” to store the student’s date of birth
A private integer class variable named numberOfStudents that keeps track of the number of students that have been created so far
A public constructor Person(String name, int UFID, String dob)
Several public get/set methods for all the properties
getName/setName
getUFID/setUFID
getDob/setDob
Part II: (15 pts) Create a Course class with the following:
A private String variable named “name” to store the course’s name, such as COP3502 etc.
A private array named “students” Student[] students.
A private integer variable “capacity” for the maximum number of students allowed in this class
A private integer variable “currentEnrollment” for the number of students enrolled in the course right now
A private integer class variable named numberOfCourses that keeps track of the number of courses that have been created so far
A public constructor Course(String n, int cap)
Several set/set methods for all the properties
getName/setName
getCap/setCap
etc.
A public method enrollStudent (Student s) to add s to this course and return true if the student was successfully added, or false if not
A public method removeStudent(Student s) to remove s from the students array
Part III: (20 pts) Create a test class to check whether above classes work properly. It should be able to create Course and Student objects, enroll student or drop student to these courses, printout current enrolled courses for a given student.
Explanation / Answer
public class Student { 02 private String name; 03 private int UFID; 04 private String DOB; 05 private static int number; 06 07 //Constructors 08 Student(String name, int UFID, String DOB) { 09 this.name = name; 10 this.UFID = UFID; 11 this.DOB = DOB; 12 } 13 14 //Get and set methods for all properties 15 String getName() { 16 return name; 17 } 18 public void setName(String newName) { 19 name = newName; 20 } 21 int getUFID() { 22 return UFID; 23 } 24 public void setUFID(int newUFID) { 25 UFID = newUFID; 26 } 27 String getDOB() { 28 return DOB; 29 } 30 public void setDOB(String newDOB) { 31 DOB = newDOB; 32 } 33 } ii) 01 public class Course { 02 private String name; //Name of course 03 private Student[] students = new Student[5]; 04 private int capacity; //Number of students allowed in course 05 private static int currentEnrollment; //number of students enrolled 06 private static int numberOfCourses; //Number of courses created so far 07 08 //Constructor 09 Course(String n, int cap) { 10 name = n; 11 capacity = cap; 12 } 13 14 //Get and set methods 15 String getName() { 16 return name; 17 } 18 public void setName(String newName) { 19 name = newName; 20 } 21 int getCapacity() { 22 return capacity; 23 } 24 public void setCapacity(int newCapacity) { 25 capacity = newCapacity; 26 } 27 28 //Method to add a student (s) to the course and return true if added and false if not 29 public static boolean addStudent(Student s) { 30 if (capacity - currentEnrollment > 0) { //See if class has room 31 32 return true; 33 } 34 else { 35 return false; 36 } 37 38 //Method to remove student from a class 39
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.