Question: import java.util.Scanner; class Student { private String firstName; private String lastName; private String idNumber; private String major; / / Set methods public void setFirstName (

import java.util.Scanner;
class Student {
private String firstName;
private String lastName;
private String idNumber;
private String major;
// Set methods
public void setFirstName(String fName){
this.firstName = fName;
}
public void setLastName(String lName){
this.lastName = lName;
}
public void setIdNumber(String id){
this.idNumber = id;
}
public void setMajor(String m){
this.major = m;
}
// Get methods
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getIdNumber(){
return idNumber;
}
public String getMajor(){
return major;
}
}
public class Program2Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
// Create an instance of the Student class
Student myStudent = new Student();
// Request information from the user
System.out.print("Please enter your first name: ");
String fName = scanner.nextLine();
System.out.print("Please enter your last name: ");
String lName = scanner.nextLine();
System.out.print("Please enter your id number: ");
String id = scanner.nextLine();
System.out.print("Please enter your major: ");
String m = scanner.nextLine();
// Set the values using set methods
myStudent.setFirstName(fName);
myStudent.setLastName(lName);
myStudent.setIdNumber(id);
myStudent.setMajor(m);
// Display the student's information
System.out.println("
Student Information:");
System.out.println("First Name: "+ myStudent.getFirstName());
System.out.println("Last Name: "+ myStudent.getLastName());
System.out.println("ID Number: "+ myStudent.getIdNumber());
System.out.println("Major: "+ myStudent.getMajor());
// Close the scanner
scanner.close();
}For this assignment we will be creating a program with a separate class. Save the project as
firstNameProgram2. Create a class called Student that used the private variables String
firstName, String lastName, String idNumber, String and major. The class should include set
and get methods for all the private variables of the class.
You will also create a main called program2Main. Inside of the main create a copy of the
Student class called myStudent. Use the main to request the required information from the
user and store it in String variables fName, IName, id,m(be sure to use nextLine() and not just
next(). Next does not read spaces). Use the set methods from the class (i.e., setFirstName,
setLastName, setIdNumber, and setMajor) to store the values entered by the user into the
myStudent class in its private variables. Using the get methods of the myStudent class (i.e.,
getFirstName, getLastName, getIdNumber, and getMajor), display the student's information
neatly on the console.
See example of console display below:
Please enter your first name:
Helen
Please enter your last name:
Thomas
Please enter your id number:
123456789
Please enter your major:
Computer Science
First Name: Helen
Last Name: Thomas
ID Number: 123456789
Major: Computer Science
 import java.util.Scanner; class Student { private String firstName; private String lastName;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!