SlideShare a Scribd company logo
1 of 14
Download to read offline
Hello. I'm currently working on the last section to my assignment and I'm running into issues.
I'll post a screenshot of the directions provided to us, my 5 classes, and a screenshot of my
console output. Can you help me fix my code? I don't know where it's going wrong and I can't
figure it out. Please leave comments on what I did wrong so I can learn from it. Thank you so
much!
Here is the instructions from the pdf for reference on what I'm trying to accomplish.
package campus;
public class Person {
private String id;
private String lastName;
private String firstName;
public Person(String id, String last, String first)
{
this.id = id;
this.lastName = last;
this.firstName = first;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getId() {
return id;
}
public String toString()
{
return id + ": " + firstName + " " + lastName;
}
}
------
---Student.java---
package campus;
public class Student extends Person {
private String major;
private int level;
private Person obj;
public Student(String id, String last, String first, String focus, int level) {
super(id, last, first);// calling parent constructor
this.major = focus;
this.level = level;
obj = new Person(id, last, first);
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
@Override
public String toString() { // override toString() method
return "id: " + obj.getId() + ", Name: " + obj.getFirstName() + " " + obj.getLastName()
+ ", major is "
+ this.major + " and their level is " + this.level;
}
}
------
---Faculty.java---
package campus;
public class Faculty extends Person {
private String dept;
private String rank;
private Person obj;
public Faculty(String id, String last, String first, String focus, int level) {
super(id, last, first);// calling parent constructor
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public String getRank() {
return rank;
}
public void setRank(int level) {
this.rank = rank;
}
@Override
public String toString() { // override toString() method
return "id: " + obj.getId() + ", Name: " + obj.getFirstName() + " " + obj.getLastName()
+ ", deptartment is "
+ this.dept + " and their rank is " + this.rank;
}
}
------
---Section.java---
package campus;
public class Section {
private String id;
private Faculty instructor;
private Student[] enrolled;
private int numofEnroll;
private int capacity;
private String location;
private String time;
private String semester;
public Section(String id, Faculty instructor, int capacity, String location, String time, String
semester) {
}
public Section(String id, int capacity) {
this.id = id;
this.capacity = capacity;
this.numofEnroll = 0;
this.enrolled = new Student[capacity];
}
public String getId() {
return id;
}
public Faculty getInstructor() {
return instructor;
}
public void setInstructor(Faculty instructor) {
this.instructor = instructor;
}
public Student[] getEnrolled() {
return enrolled;
}
public int getNumofEnroll() {
return numofEnroll;
}
public int getCapacity() {
return capacity;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getSemester() {
return semester;
}
public void enrollStudent(Student newStudent) {
// check is capacity is equal to enrolled list
if (numofEnroll == capacity) {
System.out.println("Section capacity is full");
} else {
enrolled[numofEnroll] = newStudent;
numofEnroll++;
}
}
public void removeStudent(Student newStudent) {
// first check if the student is exist in the section or not
boolean found = false;
for (int i = 0; i < enrolled.length; i++) {
if (enrolled[i].getId().equalsIgnoreCase(newStudent.getId())) {
// found, now delete the student
enrolled[i] = null;
found = true;
}
}
if (!found)
System.out.println("requested Student is not found in the section");
}
public void displayStudents() {
for (int i = 0; i < enrolled.length; i++) {
if (enrolled[i] != null) {
System.out.println(enrolled[i]);
}
}
}
public void printRoster() {
System.out.println("Section: " + id + " " + "Instructor: " + instructor + " Capacity: " +
capacity
+ " Enrolled: " + numofEnroll + " Location: " + " Semester: " + semester + "
Meeting time: "
+ time + " Student's ID Student's Name Student's Major Student's Level");
}
}
------
---TestCampus.java---
package campus;
public class TestCampus {
public static void main(String[] args) {
Student stu1 = new Student("w3098537", "Wareberg", "James", "CSIS", 4);
Student stu2 = new Student("w1111111", "Damon", "Matt", "Theatre Arts", 3);
Student stu3 = new Student("w2222222", "Wahlberg", "Mark", "Theatre Arts", 3);
Student stu4 = new Student("w3333333", "Rowling", "Joanne", "English", 4);
Student stu5 = new Student("w4444444", "Beckham", "David", "Exercise and Sport
Science", 3);
Student stu6 = new Student("w555555", "Obama", "Barack", "Political Science", 5);
Faculty fac1 = new Faculty("w3029699", "Dai", "Ruxin", "CSIS", 5);
Section section = new Section("235-1", fac1, 5, "North Hall", "8:00am", "Spring");
section.printRoster();
section.enrollStudent(stu1);
section.enrollStudent(stu2);
section.enrollStudent(stu3);
section.enrollStudent(stu4);
section.enrollStudent(stu5);
section.enrollStudent(stu6);
section.displayStudents();
// now delete the student from enroll list
System.out.println("removing student: " + stu1);
section.removeStudent(stu1);
System.out.println(" All Student in the Section:");
System.out.println("---------------------------");
section.displayStudents();
}
}
------
My output when I compile the program. 4. Define a class Section, which has a Faculty as
instructor and a collection of students enrolled. The class should contain: Instance variables: id
(String), instructor (Faculty), enrolled (Student0), numo Enroll (int), capacity (int), location
(String), time (String), semester (String) Constructor public Section (String id Faculty instructor,
int capacity String location, String time, String semester) Note: the above constructor is used to
create a section with determined id, instructor, capacity, location, time and semester, but no
enrolled student yet.
Solution
Following mistakes found in your code:
1. In Section.java class the two filed constructor is not called to initialize below files
this.id = id;
this.capacity = capacity;
this.numofEnroll = 0;
this.enrolled = new Student[capacity];
Due to uninitialized id,capacity Y enrolled filed cause Null pointer exception.
2. Also in Person.java & Student.java class you had created instance of Person class as
composition
but its not good practice to have it as inheritance gives you those filed.
3. In Faculty.java class setRank method had mistakes.
I think this will solve your problem.
Following is corrected java code:
//Person.java file
package campus;
public class Person {
private String id;
private String lastName;
private String firstName;
public Person(String id, String last, String first) {
this.id = id;
this.lastName = last;
this.firstName = first;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getId() {
return id;
}
public String toString() {
return id + ": " + firstName + " " + lastName;
}
}
//Student.java file
package campus;
public class Student extends Person {
private String major;
private int level;
public Student(String id, String last, String first, String focus, int level) {
super(id, last, first);// calling parent constructor
this.major = focus;
this.level = level;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
@Override
public String toString() { // override toString() method
return super.getId() + "tt" + super.getFirstName() + " " + super.getLastName() +
"tt"+ this.level+"tt" +this.major;
}
}
//Faculty.java file
package campus;
public class Faculty extends Person {
private String dept;
private int rank;
//The dept & rank parameters initialized
public Faculty(String id, String last, String first, String dept, int rank) {
super(id, last, first);// calling parent constructor
this.dept=dept;
this.rank=rank;
}
public String getDept() {
return dept;
}
public void setDept(String dept) {
this.dept = dept;
}
public int getRank() {
return rank;
}
// Here setRank was wrong. Corrected it
public void setRank(int rank) {
this.rank = rank;
}
@Override
public String toString() { // override toString() method
return "id: " + super.getId() + ", Name: " + super.getFirstName() + " " +
super.getLastName() + ", deptartment is "
+ this.dept + " and their rank is " + this.rank;
}
}
//Section.java file
package campus;
public class Section {
private String id;
private Faculty instructor;
private Student[] enrolled;
private int numofEnroll;
private int capacity;
private String location;
private String time;
private String semester;
public Section(String id, Faculty instructor, int capacity, String location, String time, String
semester) {
//Here calling to two field constructor to create
//student enrolled array with size capacity.
this(id, capacity);
this.instructor=instructor;
this.location=location;
this.time=time;
this.semester=semester;
}
public Section(String id, int capacity) {
this.id = id;
this.capacity = capacity;
this.numofEnroll = 0;
this.enrolled = new Student[capacity];
}
public String getId() {
return id;
}
public Faculty getInstructor() {
return instructor;
}
public void setInstructor(Faculty instructor) {
this.instructor = instructor;
}
public Student[] getEnrolled() {
return enrolled;
}
public int getNumofEnroll() {
return numofEnroll;
}
public int getCapacity() {
return capacity;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getSemester() {
return semester;
}
public void enrollStudent(Student newStudent) {
// check is capacity is equal to enrolled list
if (numofEnroll == capacity) {
System.out.println("Section capacity is full");
} else {
enrolled[numofEnroll] = newStudent;
numofEnroll++;
}
}
public void removeStudent(Student newStudent) {
// first check if the student is exist in the section or not
boolean found = false;
for (int i = 0; i < enrolled.length; i++) {
if (enrolled[i].getId().equalsIgnoreCase(newStudent.getId())) {
// found, now delete the student
enrolled[i] = null;
found = true;
}
}
if (!found)
System.out.println("requested Student is not found in the section");
}
public void displayStudents() {
for (int i = 0; i < enrolled.length; i++) {
if (enrolled[i] != null) {
System.out.println(enrolled[i]);
}
}
}
public void printRoster() {
System.out.println("Section: " + id + "t" + "Instructor: Name-" + instructor.getFirstName()
+" and Dept-"+instructor.getDept()+ " Capacity: " + capacity
+ "tEnrolled: " + numofEnroll + " Location: "+location + "tSemester: " + semester + "
Meeting time: "
+ time);
}
}
//TestCampus.java
package campus;
public class TestCampus {
public static void main(String[] args) {
Student stu1 = new Student("w3098537", "Wareberg", "James", "CSIS", 4);
Student stu2 = new Student("w1111111", "Damon", "Matt", "Theatre Arts", 3);
Student stu3 = new Student("w2222222", "Wahlberg", "Mark", "Theatre Arts", 3);
Student stu4 = new Student("w3333333", "Rowling", "Joanne", "English", 4);
Student stu5 = new Student("w4444444", "Beckham", "David", "Exercise and Sport
Science", 3);
Student stu6 = new Student("w555555", "Obama", "Barack", "Political Science", 5);
Faculty fac1 = new Faculty("w3029699", "Dai", "Ruxin", "CSIS", 5);
Section section = new Section("235-1", fac1, 5, "North Hall", "8:00am", "Spring");
section.enrollStudent(stu1);
section.enrollStudent(stu2);
section.enrollStudent(stu3);
section.enrollStudent(stu4);
section.enrollStudent(stu5);
section.enrollStudent(stu6);
System.out.println("-------------------------------------------------------------------------------------------
-");
section.printRoster();
System.out.println(" Student's IDttStudent's NamettStudent's LeveltStudent's
Major");
section.displayStudents();
// now delete the student from enroll list
System.out.println("Removing student:");
System.out.println("Student's IDttStudent's NamettStudent's LeveltStudent's Major");
System.out.println(stu1);
section.removeStudent(stu1);
System.out.println(" All Student in the Section:");
System.out.println("-------------------------------------------------------------------------------------------
-");
System.out.println("Student's IDttStudent's NamettStudent's LeveltStudent's
Major");
section.displayStudents();
}
}
Steps to execute the program:
1. Complie all java file using javac command
2. Run progarm using java command
Output of the program:
Section capacity is full
--------------------------------------------------------------------------------------------
Section: 235-1 Instructor: Name-Ruxin and Dept-CSIS
Capacity: 5 Enrolled: 5
Location: North Hall Semester: Spring
Meeting time: 8:00am
Student's ID Student's Name Student's Level Student's Major
w3098537 James Wareberg 4 CSIS
w1111111 Matt Damon 3 Theatre Arts
w2222222 Mark Wahlberg 3 Theatre Arts
w3333333 Joanne Rowling 4 English
w4444444 David Beckham 3 Exercise and Sport Science
Removing student:
Student's ID Student's Name Student's Level Student's Major
w3098537 James Wareberg 4 CSIS
All Student in the Section:
--------------------------------------------------------------------------------------------
Student's ID Student's Name Student's Level Student's Major
w1111111 Matt Damon 3 Theatre Arts
w2222222 Mark Wahlberg 3 Theatre Arts
w3333333 Joanne Rowling 4 English
w4444444 David Beckham 3 Exercise and Sport Science

More Related Content

Similar to Hello. Im currently working on the last section to my assignment a.pdf

Constructor&method
Constructor&methodConstructor&method
Constructor&methodJani Harsh
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)farhan amjad
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdfarishaenterprises12
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
11slide
11slide11slide
11slideIIUM
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdfrd1742
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptRithwikRanjan
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdfaplolomedicalstoremr
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfarjuncp10
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptxEpsiba1
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfakankshasorate1
 

Similar to Hello. Im currently working on the last section to my assignment a.pdf (20)

Constructor&method
Constructor&methodConstructor&method
Constructor&method
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf29. Code an application program that keeps track of student informat.pdf
29. Code an application program that keeps track of student informat.pdf
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Java OO Revisited
Java OO RevisitedJava OO Revisited
Java OO Revisited
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
11slide
11slide11slide
11slide
 
Preexisting code, please useMain.javapublic class Main { p.pdf
Preexisting code, please useMain.javapublic class Main {    p.pdfPreexisting code, please useMain.javapublic class Main {    p.pdf
Preexisting code, please useMain.javapublic class Main { p.pdf
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Oop
OopOop
Oop
 
A457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.pptA457405934_21789_26_2018_Inheritance.ppt
A457405934_21789_26_2018_Inheritance.ppt
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Classes and Inheritance
Classes and InheritanceClasses and Inheritance
Classes and Inheritance
 
public class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdfpublic class Person { private String name; private int age;.pdf
public class Person { private String name; private int age;.pdf
 
constructors.pptx
constructors.pptxconstructors.pptx
constructors.pptx
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
Java Concepts
Java ConceptsJava Concepts
Java Concepts
 
php_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdfphp_final_sy_semIV_notes_vision.pdf
php_final_sy_semIV_notes_vision.pdf
 

More from irshadkumar3

Describe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdfDescribe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdfirshadkumar3
 
A woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdfA woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdfirshadkumar3
 
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdfA 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdfirshadkumar3
 
Use the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdfUse the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdfirshadkumar3
 
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdfWhich of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdfirshadkumar3
 
What are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdfWhat are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdfirshadkumar3
 
what are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdfwhat are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdfirshadkumar3
 
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdfUsing Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdfirshadkumar3
 
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdfThe _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdfirshadkumar3
 
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdfThe functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdfirshadkumar3
 
Silica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdfSilica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdfirshadkumar3
 
Rank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdfRank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdfirshadkumar3
 
Compare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdfCompare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdfirshadkumar3
 
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdfPROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdfirshadkumar3
 
please help! READ th.pdf
please help! READ th.pdfplease help! READ th.pdf
please help! READ th.pdfirshadkumar3
 
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdfIn 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdfirshadkumar3
 
Identify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdfIdentify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdfirshadkumar3
 
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdfIA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdfirshadkumar3
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfirshadkumar3
 
How do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdfHow do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdfirshadkumar3
 

More from irshadkumar3 (20)

Describe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdfDescribe the three ways in which protists can move. Provide an examp.pdf
Describe the three ways in which protists can move. Provide an examp.pdf
 
A woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdfA woman with type O blood gave birth to a baby, also with type O bloo.pdf
A woman with type O blood gave birth to a baby, also with type O bloo.pdf
 
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdfA 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
A 15 (ww) solution of BaCl2 in water has a density of 1.12 gmL..pdf
 
Use the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdfUse the Internet to research one of the four modes of transportation.pdf
Use the Internet to research one of the four modes of transportation.pdf
 
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdfWhich of these worms are segmentedA.annelidsB.planariansC.rou.pdf
Which of these worms are segmentedA.annelidsB.planariansC.rou.pdf
 
What are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdfWhat are the proteins involved in this functions In lecture we dis.pdf
What are the proteins involved in this functions In lecture we dis.pdf
 
what are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdfwhat are the best way to query optimization in MYSQL.SolutionT.pdf
what are the best way to query optimization in MYSQL.SolutionT.pdf
 
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdfUsing Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
Using Social Media to Tell the Story of TOMS TOMS offers more than a.pdf
 
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdfThe _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
The _____ were Roman merchantsSolutionCorrect AnswerPlebeia.pdf
 
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdfThe functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
The functions f_1, f_2, ..., f_m defined on the interval I are said t.pdf
 
Silica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdfSilica gel is slightly acidic. Will this cause an acidic compound to.pdf
Silica gel is slightly acidic. Will this cause an acidic compound to.pdf
 
Rank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdfRank the four substances from least to most polar, Ethanol, pentanol.pdf
Rank the four substances from least to most polar, Ethanol, pentanol.pdf
 
Compare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdfCompare and contrast the main approaches for developing a WBS. Which.pdf
Compare and contrast the main approaches for developing a WBS. Which.pdf
 
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdfPROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf
PROBLEM 4 Run runTerribleLoop for one hour. You can stop the prog.pdf
 
please help! READ th.pdf
please help! READ th.pdfplease help! READ th.pdf
please help! READ th.pdf
 
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdfIn 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
In 1972 the small kingdom of Bhutan, in Asia, developed a measure of.pdf
 
Identify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdfIdentify and explain, in order of occurrence, the four primary phase.pdf
Identify and explain, in order of occurrence, the four primary phase.pdf
 
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdfIA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
IA 31 The reweycir deseers.ostains 4phaws G1,2, s, and M panes .pdf
 
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdfI am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
I am getting an errormsg 911, Level 16, State 1, Line 12 Database.pdf
 
How do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdfHow do you do the last page. How do you make the picture with the t.pdf
How do you do the last page. How do you make the picture with the t.pdf
 

Recently uploaded

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 

Recently uploaded (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 

Hello. Im currently working on the last section to my assignment a.pdf

  • 1. Hello. I'm currently working on the last section to my assignment and I'm running into issues. I'll post a screenshot of the directions provided to us, my 5 classes, and a screenshot of my console output. Can you help me fix my code? I don't know where it's going wrong and I can't figure it out. Please leave comments on what I did wrong so I can learn from it. Thank you so much! Here is the instructions from the pdf for reference on what I'm trying to accomplish. package campus; public class Person { private String id; private String lastName; private String firstName; public Person(String id, String last, String first) { this.id = id; this.lastName = last; this.firstName = first; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getId() { return id; }
  • 2. public String toString() { return id + ": " + firstName + " " + lastName; } } ------ ---Student.java--- package campus; public class Student extends Person { private String major; private int level; private Person obj; public Student(String id, String last, String first, String focus, int level) { super(id, last, first);// calling parent constructor this.major = focus; this.level = level; obj = new Person(id, last, first); } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } @Override public String toString() { // override toString() method return "id: " + obj.getId() + ", Name: " + obj.getFirstName() + " " + obj.getLastName() + ", major is " + this.major + " and their level is " + this.level; }
  • 3. } ------ ---Faculty.java--- package campus; public class Faculty extends Person { private String dept; private String rank; private Person obj; public Faculty(String id, String last, String first, String focus, int level) { super(id, last, first);// calling parent constructor } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public String getRank() { return rank; } public void setRank(int level) { this.rank = rank; } @Override public String toString() { // override toString() method return "id: " + obj.getId() + ", Name: " + obj.getFirstName() + " " + obj.getLastName() + ", deptartment is " + this.dept + " and their rank is " + this.rank; } } ------ ---Section.java--- package campus; public class Section { private String id; private Faculty instructor;
  • 4. private Student[] enrolled; private int numofEnroll; private int capacity; private String location; private String time; private String semester; public Section(String id, Faculty instructor, int capacity, String location, String time, String semester) { } public Section(String id, int capacity) { this.id = id; this.capacity = capacity; this.numofEnroll = 0; this.enrolled = new Student[capacity]; } public String getId() { return id; } public Faculty getInstructor() { return instructor; } public void setInstructor(Faculty instructor) { this.instructor = instructor; } public Student[] getEnrolled() { return enrolled; } public int getNumofEnroll() { return numofEnroll; } public int getCapacity() { return capacity; } public String getLocation() { return location; }
  • 5. public void setLocation(String location) { this.location = location; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getSemester() { return semester; } public void enrollStudent(Student newStudent) { // check is capacity is equal to enrolled list if (numofEnroll == capacity) { System.out.println("Section capacity is full"); } else { enrolled[numofEnroll] = newStudent; numofEnroll++; } } public void removeStudent(Student newStudent) { // first check if the student is exist in the section or not boolean found = false; for (int i = 0; i < enrolled.length; i++) { if (enrolled[i].getId().equalsIgnoreCase(newStudent.getId())) { // found, now delete the student enrolled[i] = null; found = true; } } if (!found) System.out.println("requested Student is not found in the section"); } public void displayStudents() { for (int i = 0; i < enrolled.length; i++) {
  • 6. if (enrolled[i] != null) { System.out.println(enrolled[i]); } } } public void printRoster() { System.out.println("Section: " + id + " " + "Instructor: " + instructor + " Capacity: " + capacity + " Enrolled: " + numofEnroll + " Location: " + " Semester: " + semester + " Meeting time: " + time + " Student's ID Student's Name Student's Major Student's Level"); } } ------ ---TestCampus.java--- package campus; public class TestCampus { public static void main(String[] args) { Student stu1 = new Student("w3098537", "Wareberg", "James", "CSIS", 4); Student stu2 = new Student("w1111111", "Damon", "Matt", "Theatre Arts", 3); Student stu3 = new Student("w2222222", "Wahlberg", "Mark", "Theatre Arts", 3); Student stu4 = new Student("w3333333", "Rowling", "Joanne", "English", 4); Student stu5 = new Student("w4444444", "Beckham", "David", "Exercise and Sport Science", 3); Student stu6 = new Student("w555555", "Obama", "Barack", "Political Science", 5); Faculty fac1 = new Faculty("w3029699", "Dai", "Ruxin", "CSIS", 5); Section section = new Section("235-1", fac1, 5, "North Hall", "8:00am", "Spring"); section.printRoster(); section.enrollStudent(stu1); section.enrollStudent(stu2); section.enrollStudent(stu3); section.enrollStudent(stu4); section.enrollStudent(stu5); section.enrollStudent(stu6); section.displayStudents(); // now delete the student from enroll list
  • 7. System.out.println("removing student: " + stu1); section.removeStudent(stu1); System.out.println(" All Student in the Section:"); System.out.println("---------------------------"); section.displayStudents(); } } ------ My output when I compile the program. 4. Define a class Section, which has a Faculty as instructor and a collection of students enrolled. The class should contain: Instance variables: id (String), instructor (Faculty), enrolled (Student0), numo Enroll (int), capacity (int), location (String), time (String), semester (String) Constructor public Section (String id Faculty instructor, int capacity String location, String time, String semester) Note: the above constructor is used to create a section with determined id, instructor, capacity, location, time and semester, but no enrolled student yet. Solution Following mistakes found in your code: 1. In Section.java class the two filed constructor is not called to initialize below files this.id = id; this.capacity = capacity; this.numofEnroll = 0; this.enrolled = new Student[capacity]; Due to uninitialized id,capacity Y enrolled filed cause Null pointer exception. 2. Also in Person.java & Student.java class you had created instance of Person class as composition but its not good practice to have it as inheritance gives you those filed. 3. In Faculty.java class setRank method had mistakes. I think this will solve your problem. Following is corrected java code: //Person.java file package campus; public class Person { private String id; private String lastName;
  • 8. private String firstName; public Person(String id, String last, String first) { this.id = id; this.lastName = last; this.firstName = first; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getId() { return id; } public String toString() { return id + ": " + firstName + " " + lastName; } } //Student.java file package campus; public class Student extends Person { private String major; private int level; public Student(String id, String last, String first, String focus, int level) { super(id, last, first);// calling parent constructor this.major = focus; this.level = level; } public String getMajor() {
  • 9. return major; } public void setMajor(String major) { this.major = major; } public int getLevel() { return level; } public void setLevel(int level) { this.level = level; } @Override public String toString() { // override toString() method return super.getId() + "tt" + super.getFirstName() + " " + super.getLastName() + "tt"+ this.level+"tt" +this.major; } } //Faculty.java file package campus; public class Faculty extends Person { private String dept; private int rank; //The dept & rank parameters initialized public Faculty(String id, String last, String first, String dept, int rank) { super(id, last, first);// calling parent constructor this.dept=dept; this.rank=rank; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public int getRank() {
  • 10. return rank; } // Here setRank was wrong. Corrected it public void setRank(int rank) { this.rank = rank; } @Override public String toString() { // override toString() method return "id: " + super.getId() + ", Name: " + super.getFirstName() + " " + super.getLastName() + ", deptartment is " + this.dept + " and their rank is " + this.rank; } } //Section.java file package campus; public class Section { private String id; private Faculty instructor; private Student[] enrolled; private int numofEnroll; private int capacity; private String location; private String time; private String semester; public Section(String id, Faculty instructor, int capacity, String location, String time, String semester) { //Here calling to two field constructor to create //student enrolled array with size capacity. this(id, capacity); this.instructor=instructor; this.location=location; this.time=time; this.semester=semester; } public Section(String id, int capacity) { this.id = id;
  • 11. this.capacity = capacity; this.numofEnroll = 0; this.enrolled = new Student[capacity]; } public String getId() { return id; } public Faculty getInstructor() { return instructor; } public void setInstructor(Faculty instructor) { this.instructor = instructor; } public Student[] getEnrolled() { return enrolled; } public int getNumofEnroll() { return numofEnroll; } public int getCapacity() { return capacity; } public String getLocation() { return location; } public void setLocation(String location) { this.location = location; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getSemester() { return semester;
  • 12. } public void enrollStudent(Student newStudent) { // check is capacity is equal to enrolled list if (numofEnroll == capacity) { System.out.println("Section capacity is full"); } else { enrolled[numofEnroll] = newStudent; numofEnroll++; } } public void removeStudent(Student newStudent) { // first check if the student is exist in the section or not boolean found = false; for (int i = 0; i < enrolled.length; i++) { if (enrolled[i].getId().equalsIgnoreCase(newStudent.getId())) { // found, now delete the student enrolled[i] = null; found = true; } } if (!found) System.out.println("requested Student is not found in the section"); } public void displayStudents() { for (int i = 0; i < enrolled.length; i++) { if (enrolled[i] != null) { System.out.println(enrolled[i]); } } } public void printRoster() { System.out.println("Section: " + id + "t" + "Instructor: Name-" + instructor.getFirstName() +" and Dept-"+instructor.getDept()+ " Capacity: " + capacity + "tEnrolled: " + numofEnroll + " Location: "+location + "tSemester: " + semester + " Meeting time: " + time);
  • 13. } } //TestCampus.java package campus; public class TestCampus { public static void main(String[] args) { Student stu1 = new Student("w3098537", "Wareberg", "James", "CSIS", 4); Student stu2 = new Student("w1111111", "Damon", "Matt", "Theatre Arts", 3); Student stu3 = new Student("w2222222", "Wahlberg", "Mark", "Theatre Arts", 3); Student stu4 = new Student("w3333333", "Rowling", "Joanne", "English", 4); Student stu5 = new Student("w4444444", "Beckham", "David", "Exercise and Sport Science", 3); Student stu6 = new Student("w555555", "Obama", "Barack", "Political Science", 5); Faculty fac1 = new Faculty("w3029699", "Dai", "Ruxin", "CSIS", 5); Section section = new Section("235-1", fac1, 5, "North Hall", "8:00am", "Spring"); section.enrollStudent(stu1); section.enrollStudent(stu2); section.enrollStudent(stu3); section.enrollStudent(stu4); section.enrollStudent(stu5); section.enrollStudent(stu6); System.out.println("------------------------------------------------------------------------------------------- -"); section.printRoster(); System.out.println(" Student's IDttStudent's NamettStudent's LeveltStudent's Major"); section.displayStudents(); // now delete the student from enroll list System.out.println("Removing student:"); System.out.println("Student's IDttStudent's NamettStudent's LeveltStudent's Major"); System.out.println(stu1); section.removeStudent(stu1); System.out.println(" All Student in the Section:"); System.out.println("------------------------------------------------------------------------------------------- -");
  • 14. System.out.println("Student's IDttStudent's NamettStudent's LeveltStudent's Major"); section.displayStudents(); } } Steps to execute the program: 1. Complie all java file using javac command 2. Run progarm using java command Output of the program: Section capacity is full -------------------------------------------------------------------------------------------- Section: 235-1 Instructor: Name-Ruxin and Dept-CSIS Capacity: 5 Enrolled: 5 Location: North Hall Semester: Spring Meeting time: 8:00am Student's ID Student's Name Student's Level Student's Major w3098537 James Wareberg 4 CSIS w1111111 Matt Damon 3 Theatre Arts w2222222 Mark Wahlberg 3 Theatre Arts w3333333 Joanne Rowling 4 English w4444444 David Beckham 3 Exercise and Sport Science Removing student: Student's ID Student's Name Student's Level Student's Major w3098537 James Wareberg 4 CSIS All Student in the Section: -------------------------------------------------------------------------------------------- Student's ID Student's Name Student's Level Student's Major w1111111 Matt Damon 3 Theatre Arts w2222222 Mark Wahlberg 3 Theatre Arts w3333333 Joanne Rowling 4 English w4444444 David Beckham 3 Exercise and Sport Science