import java.io.*; public class Department { private int numberStudents; private String deptName; // default constructor public Department() { deptName = "ACAE"; numberStudents = 100; } // specific constructor public Department(int i, String s) { deptName = s; numberStudents = i; } //accessors public String getName(){ return deptName; } public int getNumber(){ return numberStudents; } //mutators public void setName(String s){ deptName = s; } public void setNumber(int n){ numberStudents = n; } //main method to use this class public static void main(String args[]) throws IOException{ //construct an object using default constructor Department d1 = new Department(); //output the initial values System.out.println("by default, the department name is " + d1.getName()); System.out.println("by default, the number of students is " + d1.getNumber()); //using user's input to change the department System.out.println("please input the new department name"); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); //get the input, which is a string String a = stdin.readLine(); //try to use a loop to continue changing the name untill user input s to stop while(!a.equals("s")){ //to compare two objects equals or not, use the method, "==" will not work //use a mutator to change the name d1.setName(a); //output the new name System.out.println("new department name is " + d1.deptName); System.out.println("please input the new department name(input s to stop the loop)"); a = stdin.readLine(); } } }