This program is implemented by Sahil Btech(CSE) from JP University, Noida
import java.util.Scanner;
class Employee
{
// non static data members of employee
String name;
String desig;
double salary;
String city;
// non static method to store data of employee
void set_employee_info()
{
// scanner to get input from keyboard`
Scanner sc=new Scanner(System.in);
System.out.print("Enter name: ");
name=sc.next(); // get string from keyboard
System.out.print("Enter Designation: ");
desig=sc.next(); // get string from keyboard
System.out.print("Enter Salary: ");
salary=sc.nextDouble(); // get a double type value from keyboard
System.out.print("Enter City: ");
city=sc.next(); // get string from keyboard
}
// non static method to store data of employee
void show_emp_info()
{
System.out.println("Name: "+name);
System.out.println("Designation: "+desig);
System.out.println("Salary: "+salary);
System.out.println("City: "+city);
}
public static void main(String[] args) {
// scanner to get input from keyboard
Scanner sc=new Scanner(System.in);
System.out.print("How many employees do you want: ");
int num=sc.nextInt(); // get int value from keyboard
// create array of employee to store multiple employee object
Employee[] emp=new Employee[num];
System.out.println("array of employee of size "+num+" has been created");
for(int i=0;i<num;i++)
{
System.out.println("enter Record number "+(i+1));
// create object of employee
Employee e=new Employee();
// store data inside the object of employee using method
e.set_employee_info();
// store object of employee inside the array of employee
emp[i]=e;
}
System.out.println("---------------------print employee details-------------------------------");
for (int i = 0; i < emp.length; i++)
{
System.out.println("Record number "+(i+1)+"->");
// call method show_emp_info() on ith element of employee array
emp[i].show_emp_info();
System.out.println("-----------------------------------------------------------");
}
}
}
import java.util.Scanner;
class Employee
{
// non static data members of employee
String name;
String desig;
double salary;
String city;
// non static method to store data of employee
void set_employee_info()
{
// scanner to get input from keyboard`
Scanner sc=new Scanner(System.in);
System.out.print("Enter name: ");
name=sc.next(); // get string from keyboard
System.out.print("Enter Designation: ");
desig=sc.next(); // get string from keyboard
System.out.print("Enter Salary: ");
salary=sc.nextDouble(); // get a double type value from keyboard
System.out.print("Enter City: ");
city=sc.next(); // get string from keyboard
}
// non static method to store data of employee
void show_emp_info()
{
System.out.println("Name: "+name);
System.out.println("Designation: "+desig);
System.out.println("Salary: "+salary);
System.out.println("City: "+city);
}
public static void main(String[] args) {
// scanner to get input from keyboard
Scanner sc=new Scanner(System.in);
System.out.print("How many employees do you want: ");
int num=sc.nextInt(); // get int value from keyboard
// create array of employee to store multiple employee object
Employee[] emp=new Employee[num];
System.out.println("array of employee of size "+num+" has been created");
for(int i=0;i<num;i++)
{
System.out.println("enter Record number "+(i+1));
// create object of employee
Employee e=new Employee();
// store data inside the object of employee using method
e.set_employee_info();
// store object of employee inside the array of employee
emp[i]=e;
}
System.out.println("---------------------print employee details-------------------------------");
for (int i = 0; i < emp.length; i++)
{
System.out.println("Record number "+(i+1)+"->");
// call method show_emp_info() on ith element of employee array
emp[i].show_emp_info();
System.out.println("-----------------------------------------------------------");
}
}
}
No comments:
Post a Comment