Answer:
// Student class is defined
public class Student{
// student properties is defined
int studentID;
String firstName;
String lastName;
String major;
// student constructor is defined
public Student(int studentIdentity, String fName, String lName, String studentMajor){
studentID = studentIdentity;
firstName = fName;
lastName = lName;
major = studentMajor;
}
// setter method for studentID
public void setStudentID(int studentIdentity){
studentID = studentIdentity;
}
// setter method for firstName
public void setFirstName(String fName){
firstName = fName;
}
// setter method for lastName
public void setLastName(String lName){
lastName = lName;
}
// setter method for major
public void setMajor(String studentMajor){
major = studentMajor;
}
// getter method for studentID
public int getStudentID(){
return studentID;
}
// getter method for firstName
public String getFirstName(){
return firstName;
}
// getter method for lastName
public String getLastName(){
return lastName;
}
// getter method for major
public String getMajor(){
return major;
}
// displayMessage method to display class property in a better format
public void displayMessage(){
System.out.printf("The detail of students is shown below:\\The name of the student is: %s %s!\\The major is: %s.", getFirstName(), getLastName(), getMajor());
}
}
// main class for student is defined
public class StudentMain{
// main method that signify beginning of program execution
public static void main(String[] args) {
// object of Student is created
Student student1 = new Student(1111, "John", "Smith", "Computer Science");
Student student2 = new Student(1234, "Joe", "Doe", "Literature");
// the object is displayed by called displayMessage method
student1.displayMessage();
student2.displayMessage();
}
}
Step-by-step explanation:
The code is written in Java and well commented. It contains two class. The first section is Student.java and the second section is the StudentMain.java; it contains the main method which begins program execution.