My code keeps terminating when I compile it \"lab1.School@7852e922\" School.java
ID: 3892179 • Letter: M
Question
My code keeps terminating when I compile it
"lab1.School@7852e922"
School.java
package lab1;
public class School {
private String schoolName;
public School(String schoolName) {
this.schoolName = schoolName;
}
public String getSchoolName() {
return this.schoolName;
}
public void setSchoolName(String schoolName) {
this.schoolName = schoolName;
}
public static void main(String[] args) {
School hogwarts = new School("Hogwarts School of Witchcraft and Wizardry");
House gryffindor = new House("Gryffindor", "RED");
House slytherin = new House("Slytherin", "GREEN");
House hufflepuff = new House("Hufflepuff", "YELLOW");
House ravenclaw = new House("Ravenclaw", "BLUE");
Student harryPotter = new Student("Harry Potter", 2);
Student ronaldWeasley = new Student("Ron Weasley", 2);
Student dracoMalfoy = new Student("Draco Malfoy", 2);
Student lunaLovegood = new Student("Luna Lovegood", 1);
Student cedricDiggory = new Student("Cedric Diggory", 3);
gryffindor.addStudent(harryPotter);
gryffindor.addStudent(ronaldWeasley);
slytherin.addStudent(dracoMalfoy);
ravenclaw.addStudent(lunaLovegood);
hufflepuff.addStudent(cedricDiggory);
hogwarts.addHouse(gryffindor);
hogwarts.addHouse(slytherin);
hogwarts.addHouse(hufflepuff);
hogwarts.addHouse(ravenclaw);
System.out.println(hogwarts);
}
private void addHouse(House house) {
}
}
House.java
package lab1;
public class House {
String houseName;
String houseColor;
String[] studentArray = new String[9];
public House(String houseName, String houseColor) {
this.houseName = houseName;
this.houseColor = houseColor;
}
public String getHouseName() {
return this.houseName;
}
public void setHouseName(String houseName) {
this.houseName = houseName;
}
public String getHouseColor() {
return this.houseColor;
}
public void setHouseColor(String houseColor) {
this.houseColor = houseColor;
}
public void addStudent(Student studentName) {
}
}
Student.java
package lab1;
public class Student {
String studentName;
int studentYear;
public Student(String studentName, int studentYear) {
this.studentName = studentName;
this.studentYear = studentYear;
}
public String getStudentName() {
return this.studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getStudentYear() {
return this.studentYear;
}
public void setStudentYear(int studentYear) {
this.studentYear = studentYear;
}
}
Explanation / Answer
It is not terminating, your code's compilation is getting completed so it is showing build properly, not terminating.
your code will terminate after compilation and it is not showing anything because:
private void addHouse(House house) {
}
public void addStudent(Student studentName) {
}
these functions are empty, so values are not getting strored.
In the last Line : "System.out.println(hogwarts);" it will not show any details of hogwarts school, it will show you "School@d93a6a5" @d93a6a5 is object is displayed as string, and it has no meaning.
you have to create a function to display Schools details in school class.
You code is fully correct just you nedd to fill everythin and agian don't try System.out.println(OBJECT), it will not show member's data, you have to create a display function, I think I am clear to you, thanks
PLEASE GIVE THUMBS UP, AND FOR ANY QUERY LEAVE COMMENT, THANKS
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.