1. Create a Student class with the following: A private String variable named “n
ID: 3634302 • Letter: 1
Question
1. 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
2. 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
3. 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
2. public class Course { private static String name; private static String[] Student=new String[10]; private static int capacity; private static int currEnroll=0; private int numOfCourses; public Course() { } public Course(String a,int cap) { name=a; capacity=cap; } public void setName(String a) { name=a; } public String getName() { return name; } public void setCapacity(int cap) { capacity=cap; } public int getCapacity() { return capacity; } public static boolean enrollStudent(String name){ if(capacity>currEnroll){ Student[currEnroll]=name; currEnroll++; return true; } else return false; } public static boolean removeStudent(String name){ int count=0; for(int i=0;capacity>0 && iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.