Answer to Question #212244 in Java | JSP | JSF for nimra

Question #212244

Design an Employee class for reading and displaying employee information, the getInfo() and displayInfo() methods will be used respectively. Where getInfo() will be a private method. Used the Concept of Encapsulation to hide the data members, Employee Consist four data members. 



1
Expert's answer
2021-07-01T10:35:12-0400
/******************************************************************************
Design an Employee class for reading and displaying employee information, 
the getInfo() and displayInfo() methods will be used respectively. Where getInfo() will be a private method. 
the Concept of Encapsulation to hide the data members, Employee Consist four data members. 
*******************************************************************************/
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		Employee e=new Employee();
		e.displayInfo();
	}
}
class Employee{
    private String fname;
    private String lname;
    private int empNo;
    private int age;
    
    private void getInfo(){
        Scanner in =new Scanner(System.in);
        System.out.print("First Name: ");
        fname=in.next();
        System.out.print("Second Name: ");
        lname=in.next();
        System.out.print("Employee number: ");
        empNo=in.nextInt();
        System.out.print("Age: ");
        age=in.nextInt();
    }
    public void displayInfo(){
        getInfo();
        System.out.println("First Name: "+fname);
        System.out.println("Second Name: "+lname);
        System.out.println("Employee number: "+empNo);
        System.out.println("Age: "+age);
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS