My program is made to add/delete/display a student/teacher, I am having trouble doing so with my student in...












-3














I have created four classes, PersonCopy, Student, Teacher, and Principal.



In PersonCopy, I create variables (firstName, lastName, etc) and have setters and getters for them and I`m using constructors. The Student class extends PersonCopy because it uses the variables created in PersonCopy for the student. The Teacher class extends the Student class, adds, removes, and displays a student from the class/course (which does NOT work). The Principal class extends the Teacher class and performs something similar to Teacher, but instead of adding, deleting, and displaying students, the Principal class adds, removes, and displays teachers (which works perfectly fine). The Main method just calls on these methods from each class and shows a menu, asking the user what they want to do. Based on the input, you get to add, remove, and display a student/teacher.



I am not able to add a student to the class. I did something similar to the method in Teacher class "addTeacherToSchool," which is not working. I tried a lot to figure out how to do this, but I`m very confused. If I can work the "addStudenttoClass" method, then the methods "deleteStudent" and "displayCourses" would work (hopefully).



Here is the code for my main program.






import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





Here is my PersonCopy class.






/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





Here is my Student class.






public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





Here is my Teacher class.






import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class








public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





Here is a snippet of code I used to add a student in Teacher class, but it did not work so I removed it.






boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)












share|improve this question









New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Incomputable, rolfl Dec 26 at 20:22


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Incomputable, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.













  • "... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
    – radarbob
    Dec 28 at 4:39
















-3














I have created four classes, PersonCopy, Student, Teacher, and Principal.



In PersonCopy, I create variables (firstName, lastName, etc) and have setters and getters for them and I`m using constructors. The Student class extends PersonCopy because it uses the variables created in PersonCopy for the student. The Teacher class extends the Student class, adds, removes, and displays a student from the class/course (which does NOT work). The Principal class extends the Teacher class and performs something similar to Teacher, but instead of adding, deleting, and displaying students, the Principal class adds, removes, and displays teachers (which works perfectly fine). The Main method just calls on these methods from each class and shows a menu, asking the user what they want to do. Based on the input, you get to add, remove, and display a student/teacher.



I am not able to add a student to the class. I did something similar to the method in Teacher class "addTeacherToSchool," which is not working. I tried a lot to figure out how to do this, but I`m very confused. If I can work the "addStudenttoClass" method, then the methods "deleteStudent" and "displayCourses" would work (hopefully).



Here is the code for my main program.






import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





Here is my PersonCopy class.






/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





Here is my Student class.






public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





Here is my Teacher class.






import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class








public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





Here is a snippet of code I used to add a student in Teacher class, but it did not work so I removed it.






boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)












share|improve this question









New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by πάντα ῥεῖ, Incomputable, rolfl Dec 26 at 20:22


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Incomputable, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.













  • "... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
    – radarbob
    Dec 28 at 4:39














-3












-3








-3







I have created four classes, PersonCopy, Student, Teacher, and Principal.



In PersonCopy, I create variables (firstName, lastName, etc) and have setters and getters for them and I`m using constructors. The Student class extends PersonCopy because it uses the variables created in PersonCopy for the student. The Teacher class extends the Student class, adds, removes, and displays a student from the class/course (which does NOT work). The Principal class extends the Teacher class and performs something similar to Teacher, but instead of adding, deleting, and displaying students, the Principal class adds, removes, and displays teachers (which works perfectly fine). The Main method just calls on these methods from each class and shows a menu, asking the user what they want to do. Based on the input, you get to add, remove, and display a student/teacher.



I am not able to add a student to the class. I did something similar to the method in Teacher class "addTeacherToSchool," which is not working. I tried a lot to figure out how to do this, but I`m very confused. If I can work the "addStudenttoClass" method, then the methods "deleteStudent" and "displayCourses" would work (hopefully).



Here is the code for my main program.






import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





Here is my PersonCopy class.






/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





Here is my Student class.






public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





Here is my Teacher class.






import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class








public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





Here is a snippet of code I used to add a student in Teacher class, but it did not work so I removed it.






boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)












share|improve this question









New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I have created four classes, PersonCopy, Student, Teacher, and Principal.



In PersonCopy, I create variables (firstName, lastName, etc) and have setters and getters for them and I`m using constructors. The Student class extends PersonCopy because it uses the variables created in PersonCopy for the student. The Teacher class extends the Student class, adds, removes, and displays a student from the class/course (which does NOT work). The Principal class extends the Teacher class and performs something similar to Teacher, but instead of adding, deleting, and displaying students, the Principal class adds, removes, and displays teachers (which works perfectly fine). The Main method just calls on these methods from each class and shows a menu, asking the user what they want to do. Based on the input, you get to add, remove, and display a student/teacher.



I am not able to add a student to the class. I did something similar to the method in Teacher class "addTeacherToSchool," which is not working. I tried a lot to figure out how to do this, but I`m very confused. If I can work the "addStudenttoClass" method, then the methods "deleteStudent" and "displayCourses" would work (hopefully).



Here is the code for my main program.






import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





Here is my PersonCopy class.






/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





Here is my Student class.






public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





Here is my Teacher class.






import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class








public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





Here is a snippet of code I used to add a student in Teacher class, but it did not work so I removed it.






boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)








import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





import java.util.Scanner;

/**
* @author 568645
*
*/

public class STPProgramMain {

static Scanner input = new Scanner(System.in);

// Create an array to hold four courses

private static String courses = new String[4];

// Create reference of each class in order to call on methods from these classes

static Principal pri = new Principal();

static Teacher teach = new Teacher();

public static void main (String args) {

// Introduction

System.out.println("========================");
System.out.println("WELCOME TO THIS PROGRAM");
System.out.println("========================");

System.out.println("");

// Create the variables

boolean repeat = true;

// Using a do-while loop, run the program and its methods

do {

showOptions();

int response = input.nextInt(); // Get response (input)

if (response == 1) {

System.out.println("");

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.println("");

// Get first name input

System.out.print("Enter the student`s first name: ");
String firstName = input.next();

// Get last name input

System.out.print("Enter the student`s last name: ");
String lastName = input.next();

// Get address input

System.out.print("Enter the student`s address: ");
String address = input.next();

// Get phone number input

System.out.print("Enter the student`s phone number: ");
String phoneNum = input.next();

// Get email input

System.out.print("Enter the student`s email: ");
String email = input.next();

// Get student ID input

System.out.print("Enter the student`s student ID: ");
String studentID = input.next();

System.out.println("");

// Create an instance to store all these input values in

Student student = new Student(firstName, lastName, address, phoneNum, email, studentID);

if (teach.addStudentToClass(courses, student)) {

System.out.println("The student has been added to the class.");

System.out.println("");

System.out.println("COURSE SELECTION");
System.out.println("----------------");

System.out.println("");

// Get period 1 course input

System.out.print("Enter " + firstName + "`s period 1 course: ");
courses[0] = input.next();

// Get period 2 course input

System.out.print("Enter " + firstName + "`s period 2 course: ");
courses[1] = input.next();

// Get period 3 course input

System.out.print("Enter " + firstName + "`s period 3 course: ");
courses[2] = input.next();

// Get period 4 course input

System.out.print("Enter " + firstName + "`s period 4 course: ");
courses[3] = input.next();

System.out.println("");

}//end if inner if

else {

System.out.println("The student cannot be added.");

System.out.println("");

}//end of else

}//end of outer if

else if (response == 2) {

// Get teacher name input

System.out.println("");

System.out.print("Enter the teacher`s name (Ms./Mr./Mrs.lastName): ");
String t = input.next();

// Get department name input

System.out.print("Enter the department name: ");
String departName = input.next();

System.out.println("");

// Create instance of Teacher class and store values from Person into array

Teacher teacher = new Teacher(t, departName);

if (pri.addTeacherToSchool(teacher)) { // Returning true

System.out.println("The teacher has been added in the school.");

System.out.println("");

// Get the teacher`s course (3) input

System.out.print("Enter " + t + "`s first course name: ");

String courseA = input.next();
teacher.setCourseA(courseA);

System.out.print("Enter " + t + "`s second course name: ");

String courseB = input.next();
teacher.setCourseB(courseB);

System.out.print("Enter " + t + "`s third course name: ");

String courseC = input.next();
teacher.setCourseC(courseC);

}//end of if

else {

System.out.println("Teacher cannot be added.");

System.out.println("");

}//end of else

}//end of else if 1

else if (response == 3) {

System.out.println("");

teach.deleteStudent();

}//end of else if 2

else if (response == 4) {

System.out.println("");

pri.deleteTeacher();

}//end of else if 3

else if (response == 5) {

System.out.println("");

pri.displayCourses();

}//end of else if 4

else if (response == 6) {

System.out.println("");

pri.displayTeacherList();

}//end of else if 5

else if (response == 7) {

System.out.println("");

System.out.println("Thank you for using this program!");

System.out.println("");

break; // Program will not proceed any further

}//end of else if 6

else {

System.out.println("");

System.out.println("Invalid reply.");

System.out.println("");

}//end of else

}//end of do

while (repeat) ; {

}//end of while loop

}//main

// Method to display the options

public static void showOptions() {

System.out.println("");

System.out.println("====");
System.out.println("MENU");
System.out.println("====");

System.out.println("");

System.out.println("Type in '1' to add a STUDENT");
System.out.println("Type in '2' to add a TEACHER");
System.out.println("Type in '3' to remove a STUDENT");
System.out.println("Type in '4' to remove a TEACHER");
System.out.println("Type in '5' to view the STUDENT list");
System.out.println("Type in '6' to view the TEACHER list");
System.out.println("Type in '7' to EXIT the program");

System.out.println("");

System.out.print("Please enter your choice: ");

}//showOptions()

}//class





/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





/**
* @author 568645
*
*/
public class PersonCopy {

// Create string variables

private String firstName;
private String lastName;
private String address;
private String phoneNum; //(xxx)-xxx-xxx
private String email; //xxx.xxx.xxx

public PersonCopy() { // Like the default constructor, if this is not present

this.firstName = "Not available";
this.lastName = "Not available";
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

}//Constructor Person()

PersonCopy (String firstName, String lastName) { // Constructor with 2 parameters

this.firstName = firstName;
this.lastName = lastName;
this.address = "Not available";
this.phoneNum = "Not available";
this.email = "Not available";

} // end of Constructor 2

// Using this constructor for option 1 in person main class

PersonCopy (String firstName, String lastName, String address, String phoneNum, String email) {

this.firstName = firstName;
this.lastName = lastName;
this.address = address;
this.phoneNum = phoneNum;
this.email = email;

} // end of Constructor 3

// --------- setters and getter methods to access private data -----

void setFirstName (String firstName) { // To set private data

this.firstName = firstName;

}//setFirstName()

String getFirstName() { // To get private data

return this.firstName;

}//getFirstName()

void setLastName (String lastName) { // To set private data

this.lastName = lastName;

}//setLastName()

String getLastName() { // To get private data

return this.lastName;

}//getLastName()

void setAddress (String address) { // To set private data

this.address = address;

}//setAddress()

String getAddress() { // To get private data

return this.address;

}//getAddress()

void setPhoneNum (String phoneNum) { // To set private data

this.phoneNum = phoneNum;

}//setPhoneNum()

String getPhoneNum() { // To get private data

return this.phoneNum;

}//getPhoneNum()

void setEmail (String period2C) { // To set private data

this.email = period2C;

}//setEmail()

String getEmail() { // To get private data

return this.email;

}//getEmail()

}//end of class PersonCopy





public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





public class Student extends PersonCopy {

// Create variables

private String nameFirst;
private String nameLast;
private String studentID; // 6 digit
private String gradeNum; // 2 digit (01, 05, 10, 12, etc)
private String period1C; // Period 1 course
private String period2C; // Period 2 course
private String period3C; // Period 3 course
private String period4C; // Period 4 course

public Student() { // Like the default constructor, if this is not present

this.nameFirst = "Not Available";
this.nameLast = "Not Available";
this.studentID = "Not available";
this.gradeNum = "Not available";
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//Student()

Student (String nameFirst, String nameLast, String studentID, String gradeNum) { // Constructor with 2 parameters

this.nameFirst = nameFirst;
this.nameLast = nameLast;
this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = "Not available";
this.period2C = "Not available";
this.period3C = "Not available";
this.period4C = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Student (String nameFirst, String nameLast, String studentID, String gradeNum, String period1C, String period2C, String period3C, String period4C) {

this.studentID = studentID;
this.gradeNum = gradeNum;
this.period1C = period1C;
this.period2C = period2C;
this.period3C= period3C;
this.period4C = period4C;

}//end of Constructor 3

Student (String firstName, String lastName, String address, String phoneNum, String email, String studentID) {

super(firstName, lastName, address, phoneNum, email);

this.studentID = studentID;

}//end of Student(firstName, lastName, address, phoneNum, email)

// --------- setters and getter methods to access private data -----

void setFirstName (String nameFirst) { // To set private data

this.nameFirst = nameFirst;

}//setFirstName()

String getFirstName() { // To get private data

return this.nameFirst;

}//getFirstName()

void setLastName (String nameLast) { // To set private data

this.nameLast = nameLast;

}//setLastName()

String getLastName() { // To get private data

return this.nameLast;

}//getLastName()

void setstudentID (String studentID) { // To set private data

this.studentID = studentID;

}//setstudentID()

String getstudentID() { // To get private data

return this.studentID;

}//getstudentID()

public String getGradeNum() {

return gradeNum;

}//end of getGradeNum()

public void setGradeNum(String gradeNum) {

this.gradeNum = gradeNum;

}//end of setGradeNum

void setFirstCourse (String period1C) { // To set private data

this.period1C = period1C;

}//setFirstCourse()

String getFirstCourse() { // To get private data

return this.period1C;

}//getFirstCourse()

void setSecondCourse (String period2C) { // To set private data

this.period2C = period2C;

}//setSecondCourse()

String getSecondCourse() { // To get private data

return this.period2C;

}//getSecondCourse()

void setThirdCourse (String period3C) { // To set private data

this.period3C = period3C;

}//setThirdCourse()

String getThirdCourse() { // To get private data

return this.period3C;

}//getThirdCourse()

void setForthCourse (String period4C) { // To set private data

this.period4C = period4C;

}//setForthCourse()

String getForthCourse() { // To get private data

return this.period4C;

}//getForthCourse()

}//class





import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class





import java.util.Scanner;

public class Teacher extends Student {

static Scanner input = new Scanner(System.in);

// Create variables

private String t;
private String departName;
private String courseA;
private String courseB;
private String courseC;

protected static Teacher teacherList = new Teacher[10];

private static Student studentListA = new Student [20];
private static Student studentListB = new Student [20];
private static Student studentListC = new Student [20];

public Teacher() { // Like the default constructor, if this is not present

this.t = "Not Available";
this.departName = "Not Available";
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//Student()

Teacher(String t, String departName) { // Constructor with 2 parameters

this.t = t;
this.departName = departName;
this.courseA = "Not Available";
this.courseB = "Not available";
this.courseC = "Not available";

}//end of Constructor 2

// Using this constructor for option 1 in person main class

Teacher(String t, String departName, String courseA, String courseB, String courseC, Teacher teacherList, Student studentListA, Student studentListB, Student studentListC) {

this.t = t;
this.departName = departName;
this.courseA = courseA;
this.courseB = courseB;
this.courseC = courseC;
Teacher.teacherList = teacherList;
Teacher.studentListA = studentListA;
Teacher.studentListB= studentListB;
Teacher.studentListC = studentListC;

}//end of Constructor

// --------- setters and getter methods to access private data -----

void setTeachersName(String t){ // To set private data

this.t = t;

}//setTeachersName(t)

String getTeachersName(){ // To get private data

return t;

}//getTeachersName()

void setDepartName (String departName) { // To set private data

this.departName = departName;

}//setDepartName(departName)

String getDepartName(){ // To get private data

return departName;

}//getDepartName()

void setCourseA (String courseA) { // To set private data

this.courseA = courseA;

}//setCourseA(courseA)

String getCourseA(){ // To get private data

return courseA;

}//getCourseA()

void setCourseB (String courseB) { // To set private data

this.courseB = courseB;

}//setcourseB(courseB)

String getcourseB(){ // To get private data

return courseB;

}//getcourseB()

void setCourseC(String courseC){ // To set private data

this.courseC = courseC;

}//setcourseC(courseC)

String getcourseC(){ // To get private data

return courseC;

}//getcourseC()

void setTeacherList(Teacher teacherList) {

Teacher.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList() {

return teacherList;

}//getTeacherList

void setStudentListA(Student studentListA){ // To set private data

Teacher.studentListA = studentListA;

}//setStudentListA(studentListA)

Student getStudentListA(){ // to get private data

return Teacher.studentListA;

}//getStudentListA()

void setStudentListB(Student studentListB){ // to set private data

Teacher.studentListB = studentListB;

}//setStudentListB(studentListB)

Student getStudentListB(){ // To get private data

return Teacher.studentListB;

}//getStudentListB()

void setStudentListC(Student studentListC){ // To set private data

Teacher.studentListC = studentListC;

}//setStudentListC(studentListC)

Student getStudentListC(){ // To get private data

return Teacher.studentListC;

}//getStudentListC()

boolean addStudentToClass (String courses, Student student) {

int index = 0;

String firstName = student.getFirstName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add the student in class while the class is not full

do {

// Is the student already in the class?

if (studentListA[index] != null && studentListA[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the teacher is already in the class

isListFull = false; // false because the class is not full

// Is there room to add a student into the class?

if (studentListA[index] == null && (courses.equals(courseA))) {

// Add the student into the class

studentListA[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the class is not full

}//end of inner if

index++;

}//end of outer if

// Is the student already in the class?

if (studentListB[index] != null && studentListB[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListB[index] == null && (courses.equals(courseB))) {

// Adding student into the class...

studentListB[index] = (Student) student;

isComplete = true; // true because the teacher has been added

isListFull = false; // false because the class is not full

}//end of inner if 2

index++;

}//end of outer if 2

// Is the student already in the class?

if (studentListC[index] != null && studentListC[index].getFirstName().equalsIgnoreCase(firstName)) {

// Yes, the student is in the class

System.out.println("The student is already in the class.");

System.out.println("");

isInList = true; // true because the student is already in the class

isListFull = false; // false because the class is not full

// Is there space to add a student?

if (studentListC[index] == null && (courses.equals(courseC))) {

// Adding the student into the class...

studentListC[index] = (Student) student;

isComplete = true; // true because the student has been added

isListFull = false; // false because the list is not full

}//end of inner if 3

index++;

}//end of outer if 3

// End of do, begin while

} while (index < studentListA.length && index < studentListB.length && index < studentListC.length && isComplete == false && isInList == false); {

if (isListFull) {

System.out.println("The classroom is full of students. Cannot add anymore.");

System.out.println("");

}//end of if

return isAdded;

}//end of while loop

}//addStudentToClass(courses, student)

public void deleteStudent() {

System.out.print("Which student would you like to remove? Enter a number from 0-20: ");

int removeStudent = input.nextInt();

if (removeStudent < 20) {

for (int i = 0; i < 20; i++) {

if (studentListA[removeStudent] != null && studentListA[i] == studentListA[removeStudent]) {

studentListA[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if

if (studentListB[removeStudent] != null && studentListB[i] == studentListB[removeStudent]) {

studentListB[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 2

if (studentListC[removeStudent] != null && studentListC[i] == studentListC[removeStudent]) {

studentListC[removeStudent] = null;

System.out.println("The student has been removed.");

System.out.println("");

}//end of if 3

}//end of for loop

}//end of big if

else {

System.out.println("Not able to delete student.");

System.out.println("");

}//end of else

}//end of deleteStudent()

// Create a method to output the teacher and student`s courses along with the student name and teacher name

public void displayCourseList() {

// Create the variables for student

String firstName;
String lastName;
String address;
String email;
String phoneNum;
String studentID;

// Displaying information for the first course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseA); // displaying courseA
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListA[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListA[s].getFirstName();
lastName = studentListA[s].getLastName();
address = studentListA[s].getAddress();
email = studentListA[s].getEmail();
phoneNum = studentListA[s].getPhoneNum();
studentID = studentListA[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

// Displaying information for the second course

else if (courseB != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseB); // displaying courseB
System.out.println("Teacher`s Name: " + getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListB[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListB[s].getFirstName();
lastName = studentListB[s].getLastName();
address = studentListB[s].getAddress();
email = studentListB[s].getEmail();
phoneNum = studentListB[s].getPhoneNum();
studentID = studentListB[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if

// Displaying information for the third course

if (courseA != null) {

System.out.println("COURSE AND TEACHER INFORMATION");
System.out.println("-------------------------------");

System.out.println("Course Name A: " + courseC); // displaying courseC
System.out.println("Teacher`s Name: " +getTeachersName());
System.out.println("Department Name: " + getDepartName());

System.out.println("");

// Now to access the student lists and be able to output them onto the console

for (int s = 0; s < 20; s++) { // because each student list contains 20 students

if (studentListC[s] != null) {

// Setting the variables created above to the s element of this student list

firstName = studentListC[s].getFirstName();
lastName = studentListC[s].getLastName();
address = studentListC[s].getAddress();
email = studentListC[s].getEmail();
phoneNum = studentListC[s].getPhoneNum();
studentID = studentListC[s].getstudentID();

System.out.println("STUDENT INFORMATION");
System.out.println("-------------------");

System.out.print("Name: " + firstName);
System.out.println(" " + lastName);
System.out.println("Address: " + address);
System.out.println("Email: " + email);
System.out.println("Phone Number: " + phoneNum);
System.out.println("Student ID: " + studentID);

System.out.println("");

}//end of inner if

}//end of for loop

}//end of big else if 2

else {

System.out.println("Not able to display courses.");

System.out.println("");

}//end of else

}//end of displayCourses()

}//class





public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





public class Principal extends Teacher {

// Create string variables

private String t;

private String departName;

private String schoolName;

private Teacher teacherList = new Teacher [10];

public Principal() { // Like the default constructor, if this is not present

this.t = "Not available";
this.departName = "Not available";
this.schoolName = "Not available";

}//Principal() (end of Constructor 1)

public Principal (String t) { // Constructor with 1 parameter

this.t = t;

}//Principal(schoolName) (end of Constructor 2)

public Principal (String t, String departName) {

this.t = t;

this.departName = departName;

}//end of Principal(t, departName)

public Principal (String t, String departName, String schoolName, Teacher teacherList) {

this.t = t;;
this.departName = departName;
this.schoolName = schoolName;
this.teacherList = teacherList;

}//Principal() (end of Constructor 3)

// --------- setters and getter methods to access private data -----

void setT (String t) {

this.t = t;

}//setT(t)

String getT() {

return t;

}//getT(t)

void setDepartName (String departName) {

this.departName = departName;

}//setDepartName(departName)

String getDepartName() {

return departName;

}//getDepartName()

void setSchoolName (String schoolName) { // To set private data

this.schoolName = schoolName;

}//setSchoolName(schoolName)

String getSchoolName(){ // To get private data

return this.schoolName;

}//getSchoolName()

void setTeacherList (Teacher teacherList) { // To set private data

this.teacherList = teacherList;

}//setTeacherList(teacherList)

Teacher getTeacherList(){ // To get private data

return this.teacherList;

}//getTeacherList()

// Adding a teacher to school method

boolean addTeacherToSchool (Teacher teacher) {

int index = 0;

String t = teacher.getTeachersName();

boolean isAdded = true;

boolean isListFull = false;

boolean isInList = false;

boolean isComplete = false;

// Add teacher to school while school is not full

do {

// Is the teacher in the school?

if (teacherList[index] != null && teacherList[index].getTeachersName().equalsIgnoreCase(t)) {

// Yes. Teacher is in the list

System.out.println("Teacher is already in the school.");

System.out.println("");

isInList = true; // True because teacher is already in the list

isListFull = false; // False because the list is not full

}//end of if

// Is there space to add?

else if (teacherList[index] == null) {

// Adding the teacher into the list...

teacherList[index] = (Teacher) teacher; // Add

isComplete = true; // True because the teacher has been added

isListFull = false; // False because the list is not full

}//end of else if

index++;

// End of do, start while

} while (index < teacherList.length && isComplete == false && isInList == false) ; { // This keeps the loop going...

if (isListFull) {

System.out.println("School is full of teachers. Cannot add anymore.");

}//end of if

return isAdded;

}//end of while loop

}//addTeacherToSchool(t)

// Create a method to remove a teacher

public void deleteTeacher () {

System.out.print("Which teacher would you like to remove? Enter a number from 0-10: ");

int removeTeacher = input.nextInt();

if (removeTeacher < 10) {

for (int i = 0; i < 10; i++) {

if (teacherList[removeTeacher] != null && teacherList[i] == teacherList[removeTeacher]) {

teacherList[removeTeacher] = null;

System.out.println("The teacher has been removed.");

System.out.println("");

}//end of inner if

}//end of for loop

}//end of outer if

else {

System.out.println("Not able to delete teacher.");

}//end of else

}//delete(teacherList)

// Create a method to display the teacher using a for loop

void displayTeacherList () {

String t;
String departName;

System.out.println("TEACHER LIST");
System.out.println("------------");

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

t = teacherList[i].getTeachersName();
departName = teacherList[i].getDepartName();

System.out.println("Teacher`s Name: " + t);
System.out.println("Department Name: " + departName);

System.out.println("");

}//end of if

}//end of for loop

}//end of displayTeacherList()

// Method to display the course list in class Teacher

void displayCourses () {

for (int i = 0; i < 10; i++) {

if (teacherList[i] != null) {

System.out.println("");

teacherList[i].displayCourseList(); // Displaying the course list in TEACHER

}//end of if

}//end of for loop

}//end of displayAll(teacherList)

}//class





boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)





boolean addStudentToClass (String courses, Student student) {

boolean add = false;

for (int i = 0; i < teacherList.length; i++) {

if (teacherList[i] != null && add == false) {

Principal teacherFound = (Principal) teacherList[i]; // The teacher has been found

if (teacherFound.getFirstCourse() != null && teacherFound.getFirstCourse().equals(courses[0])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 2

}//end of inner if

else if (teacherFound.getSecondCourse() != null && teacherFound.getSecondCourse().equals(courses[1])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 3

}//end of else if

else if (teacherFound.getThirdCourse() != null && teacherFound.getThirdCourse().equals(courses[2])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 4

}//end of else if 2

else if (teacherFound.getForthCourse() != null && teacherFound.getForthCourse().equals(courses[4])) {

if (addStudentToClass(courses, student)) {

System.out.println("The student has been added to the course.");

add = true;

}//end of inner if 5

}//end of else if 3

else {

System.out.println("Course is not available.");

}//end of else

}//end of big if

}//end of for loop

if (courses.equals(courseA)) {

add = isCourseFull(studentListA, student); // Add student to student list A for course A

}//end of if

else if (courses.equals(courseB)) {

add = isCourseFull(studentListB, student); // Add student to student list B for course B

}//end of else if

else if (courses.equals(courseC)) {

add = isCourseFull(studentListC, student); // Add student to student list C for course C

}//end of else if 2

else {

System.out.println("Not able to add student to the class.");

System.out.println("");

}//end of else

return add = true;

}//end of addStudentToClass(courses, student)

// Create a method to check if the course/class is full or not, then add if it`s not full

static boolean isCourseFull (Student course, Student student) {

boolean isAdded = true;

int index = 0;

// Add student to class while course is not full

do {

if (studentListA[index] == null) {

studentListA[index] = (Student) student;

isAdded = true; // Course is not full

}//end of if

else if (studentListB[index] == null) {

studentListB[index] = (Student) student;

}//end of else if

else {

studentListC[index] = (Student) student;

}//end of else

index++; // Adding the student...

}//end of do

while (studentListA[index] != null && index < course.length) ; {

return isAdded; // Course is full

}//end of while

}//isCourseFull(course, student)






java object-oriented programming-challenge






share|improve this question









New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Dec 28 at 4:42









radarbob

5,3441026




5,3441026






New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Dec 26 at 19:45









Yashvi Shah

1




1




New contributor




Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Yashvi Shah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, Incomputable, rolfl Dec 26 at 20:22


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Incomputable, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.




put on hold as off-topic by πάντα ῥεῖ, Incomputable, rolfl Dec 26 at 20:22


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Incomputable, rolfl

If this question can be reworded to fit the rules in the help center, please edit the question.












  • "... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
    – radarbob
    Dec 28 at 4:39


















  • "... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
    – radarbob
    Dec 28 at 4:39
















"... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
– radarbob
Dec 28 at 4:39




"... which is not working. " Move your question to stack overflow, that's the best place for help with broken code.
– radarbob
Dec 28 at 4:39















active

oldest

votes






















active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

Список кардиналов, возведённых папой римским Каликстом III

Deduzione

Mysql.sock missing - “Can't connect to local MySQL server through socket”