Create a class called Employee to represent the details of an Employee. a) Include the following data members to the Employee class. EmpId, name, address (all are string data) b) Your class should have a constructor that initializes all instance variables. c) Include a method called void Read() which will input the above values from the keyboard d) Include a method called void Print() to display the properties
public class Employee {
private String emplId;
private String name;
private String address;
public Employee(String emplId, String name, String address) {
this.emplId = emplId;
this.name = name;
this.address = address;
}
public void read() {
Scanner scanner = new Scanner(System.in);
System.out.println("Empl ID:");
this.emplId = scanner.nextLine();
System.out.println("name:");
this.name = scanner.nextLine();
System.out.println("address:");
this.address = scanner.nextLine();
scanner.close();
}
public void print() {
System.out.println("Empl ID: " + this.emplId +
" name: " + this.name +
" address: " + this.address);
}
}
Comments
Leave a comment