public class ClassListBasic{
private String[] myNames;
private int myMaxEnrollment;
private int myCurrentEnrollment;
private String myCourseTitle;
public ClassListBasic(String title, int maxEnroll){
myCourseTitle = title;
myMaxEnrollment = maxEnroll;
myNames = new String[myMaxEnrollment];
myCurrentEnrollment = 0;
}
// Accessors
public int getEnrollment( ) {
return myCurrentEnrollment;
}
public int getMaxEnrollment( ) {
return myMaxEnrollment;
}
public String getTitle( ) {
return myCourseTitle;
}
public boolean inCourse (String name) {
if (searchStudent(name) == -1)
return false;
else
return true;
}
public boolean isThereRoom(){
if (myMaxEnrollment <= myCurrentEnrollment)
return false;
else
return true;
}
public void printList( ) {
System.out.print("Enrollment in " +
myCourseTitle + ": ");
for (int i = 0; i < myCurrentEnrollment; i++)
System.out.print(" " + myNames[i]);
System.out.println();
}
// modifiers
public boolean addStudent(String name){
if (searchStudent(name) != -1 || !isThereRoom())
return false;
else {
myNames[myCurrentEnrollment] = name;
myCurrentEnrollment++;
return true;
}
}
public boolean dropStudent(String name){
int loc = searchStudent(name);
if (loc == -1) return false;
for (int i = loc; i < myCurrentEnrollment-1; i++)
myNames[i] = myNames[i+1];
myCurrentEnrollment--;
return true;
}
// private helpers
private int searchStudent(String name){
for (int i = 0; i < myCurrentEnrollment; i++)
if (myNames[i].equals(name))
return i;
return -1;
}
}
|
public class ClassList{
private Student[] myNames;
private int myMaxEnrollment;
private int myCurrentEnrollment;
private String myCourseTitle;
public ClassList(String title, int maxEnroll){
myCourseTitle = title;
myMaxEnrollment = maxEnroll;
myNames = new Student[myMaxEnrollment];
myCurrentEnrollment = 0;
}
// Accessors
public int getEnrollment( ) {
return myCurrentEnrollment;
}
public int getMaxEnrollment( ) {
return myMaxEnrollment;
}
public String getTitle( ) {
return myCourseTitle;
}
public boolean inCourse (Student name) {
if (searchStudent(name) == -1)
return false;
else
return true;
}
public boolean isThereRoom(){
if (myMaxEnrollment <= myCurrentEnrollment)
return false;
else
return true;
}
public void printList( ) {
System.out.println("Enrollment in " +
myCourseTitle + ": ");
for (int i = 0; i < myCurrentEnrollment; i++)
System.out.println(" " + myNames[i]);
System.out.println();
}
// modifiers
public boolean addStudent(Student name){
if (searchStudent(name) != -1 || !isThereRoom())
return false;
else {
myNames[myCurrentEnrollment] = name;
myCurrentEnrollment++;
return true;
}
}
public boolean dropStudent(Student name){
int loc = searchStudent(name);
if (loc == -1) return false;
for (int i = loc; i < myCurrentEnrollment-1; i++)
myNames[i] = myNames[i+1];
myCurrentEnrollment--;
return true;
}
// private helpers
private int searchStudent(Student name){
for (int i = 0; i < myCurrentEnrollment; i++)
if ((myNames[i].getSSN()).equals(name.getSSN()))
return i;
return -1;
}
}
|
|
|
public class Student {
private String myFirstName;
private char myMI;
private String myLastName;
private String mySSN;
private String myMajor;
private double myGPA;
private int myCredits;
public Student (String firstName, char mi, String lastName,
String ssn, String major, double gpa, int credits){
myFirstName = firstName;
myMI = mi;
myLastName = lastName;
mySSN = ssn;
myMajor = major;
myGPA = gpa;
myCredits = credits;
}
// Accessors
public String getFirstName( ) { return myFirstName; }
public char getMI( ) { return myMI; }
public String getLastName( ) { return myLastName; }
public String getSSN( ) { return mySSN; }
public String getMajor( ) { return myMajor; }
public double getGPA( ) { return myGPA; }
public int getCredits( ) { return myCredits; }
public String toString() {
return myFirstName + " " + myMI + ". " + myLastName +
", " + mySSN + ", " + myMajor + ", " + myGPA +
", " + myCredits;
}
}
|
JohnDoe added Enrollment in CS1713: JohnDoe JaneDeer added Enrollment in CS1713: JohnDoe JaneDeer BillClinton added Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush added Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush added Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush MichaelJackson added Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush MichaelJackson RussellCrowe not added Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush MichaelJackson RussellCrowe not found Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush MichaelJackson MichaelJackson dropped Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush BarbaraBush BarbaraBush dropped Enrollment in CS1713: JohnDoe JaneDeer BillClinton GeorgeW.Bush GeorgeW.Bush dropped Enrollment in CS1713: JohnDoe JaneDeer BillClinton BillClinton dropped Enrollment in CS1713: JohnDoe JaneDeer JaneDeer dropped Enrollment in CS1713: JohnDoe JohnDoe dropped Enrollment in CS1713: |
Doe added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Deer added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Clinton added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 Bush added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Bush added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Barbara R. Bush, 312212122, EDU, 3.5, 72 Jackson added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Barbara R. Bush, 312212122, EDU, 3.5, 72 Michael X. Jackson, 123453237, MUS, 2.1, 114 Crowe not added Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Barbara R. Bush, 312212122, EDU, 3.5, 72 Michael X. Jackson, 123453237, MUS, 2.1, 114 Crowe not found Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Barbara R. Bush, 312212122, EDU, 3.5, 72 Michael X. Jackson, 123453237, MUS, 2.1, 114 Jackson dropped Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Barbara R. Bush, 312212122, EDU, 3.5, 72 Bush dropped Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 George W. Bush, 743432342, BUS, 2.5, 66 Bush dropped Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Bill C. Clinton, 345323432, BIO, 3.2, 102 Clinton dropped Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Jane B. Deer, 234345623, ENG, 2.9, 56 Deer dropped Enrollment in CS1713: John A. Doe, 327333421, CS, 3.0, 12 Doe dropped Enrollment in CS1713: |