75.8k views
3 votes
For this assignment you will create two student objects and then print out the objects values. Within the Student Class you will have the following properties: StudentID LastName FirstName Major Within the Main you will create 2 student objects by setting each of their property values. You will then write out a header line and each of the student objects to the console.

User Ldeassis
by
5.3k points

2 Answers

1 vote

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.

User Shen
by
5.6k points
5 votes

Answer:

public class Student { private String studentMajor; private String firstName; private String lastName; private int studentCredits; private int studentPoints;

Step-by-step explanation:

public class Student { private String studentMajor; private String firstName; private String lastName; private int studentCredits; private int studentPoints;

User SMAKSS
by
5.8k points