Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Student class with the following: A private String variable named “name

ID: 3634199 • Letter: C

Question

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

Explanation / Answer

http://www.dreamincode.net/forums/topic/257047-using-array-of-objects-to-add-students-to-courses/

 

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