Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 setFirstNameString fName
this.firstName fName;
public void setLastNameString lName
this.lastName lName;
public void setIdNumberString id
this.idNumber id;
public void setMajorString 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 ProgramMain
public static void mainString args
Scanner scanner new ScannerSystemin;
Create an instance of the Student class
Student myStudent new Student;
Request information from the user
System.out.printPlease enter your first name: ;
String fName scanner.nextLine;
System.out.printPlease enter your last name: ;
String lName scanner.nextLine;
System.out.printPlease enter your id number: ;
String id scanner.nextLine;
System.out.printPlease enter your major: ;
String m scanner.nextLine;
Set the values using set methods
myStudent.setFirstNamefName;
myStudent.setLastNamelName;
myStudent.setIdNumberid;
myStudent.setMajorm;
Display the student's information
System.out.println
Student Information:";
System.out.printlnFirst Name: myStudent.getFirstName;
System.out.printlnLast Name: myStudent.getLastName;
System.out.printlnID Number: myStudent.getIdNumber;
System.out.printlnMajor: myStudent.getMajor;
Close the scanner
scanner.close;
For this assignment we will be creating a program with a separate class. Save the project as
firstNameProgram 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 programMain. 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, idbe sure to use nextLine and not just
next Next does not read spaces Use the set methods from the class ie 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 ie
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:
Please enter your major:
Computer Science
First Name: Helen
Last Name: Thomas
ID Number:
Major: Computer Science
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started