Create a class called School. Include two private members representing the name
ID: 3883342 • Letter: C
Question
Create a class called School. Include two private members representing the name of the school and the number of students enrolled.
Create the appropriate accessors and mutators.
Create a default constructor that assigns the number of students to 100 and the school name to "unnamed" ,and a 2-arg constructor that will allow both attributes to be set form the declaration.
Create at least one instance using either constructor. The declarations should look as follows:
School udc, gtown("Georgetown University", 10500);
Explanation / Answer
import java.util.*;
class School{
private String schoolName;
private int numberStudents;
//constructor
public School(){
schoolName = "unnamed";
numberStudents = 100;
}
public School(String schoolName,int numberStudents){
this.schoolName = schoolName;
this.numberStudents = numberStudents;
}
//Accessors
public String getSchoolName(){
return schoolName;
}
public String getNumberStudents(){
return schoolName;
}
//Mutators
public void setSchoolName(String schoolName){
this.schoolName = schoolName;
}
public void setNumberStudents(int numberStudents){
this.numberStudents = numberStudents;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.