Answered step by step
Verified Expert Solution
Link Copied!

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 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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago