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

In the next questions, write a complete JAVA class definition for a class called

ID: 3594966 • Letter: I

Question

In the next questions, write a complete JAVA class definition for a class called School.

A school is described by: its name and whether or not it is a public school.

Use good principles of class design and encapsulation.

1.Write the class header and the instance data variable for the School class.

2.

Write two constructors:

one constructor sets the name and public status based on a parameters

a second constructor sets the name based on a parameter and uses the default value of being a public school

3.Write appropriate getter/setter methods.

4.

Write a toString method that generates a text representation in the following format:

Name: Milton Elementary

Public: true

Name: Smith Central

Public: false

Explanation / Answer

Below is your class: -

School.java

public class School {

private String schoolName;

private boolean isPublicSchool;

public School(String schlName) {

this.schoolName = schlName;

this.isPublicSchool = false;

}

School(String schlName, boolean isPubSchool) {

this.schoolName = schlName;

this.isPublicSchool = isPubSchool;

}

public String getSchoolName() {

return schoolName;

}

public void setSchoolName(String schoolName) {

this.schoolName = schoolName;

}

public boolean isPublicSchool() {

return isPublicSchool;

}

public void setPublicSchool(boolean isPublicSchool) {

this.isPublicSchool = isPublicSchool;

}

public String toString() {

return "Name: " + this.schoolName + " Public: " + this.isPublicSchool;

}

public static void main(String[] args) {

School sc1 = new School("Milton Elementary", true);

School sc2 = new School("Smith Central");

System.out.println(sc1);

System.out.println();

System.out.println(sc2);

}

}

Output_

Name: Milton Elementary
Public: true

Name: Smith Central
Public: false

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote