You are on page 1of 2

EXPERIMENT NO.

7
AIM: To implement class, object & method - II

PROBLEM STATEMENT:
Write a program that would print the information (name, year of joining, salary, address) of
three employees by creating a class named 'Employee'.

THEORY:

A class ‘Employee’ is created which has multiple methods. getInfo() method initializes the
variables passed in the parameters from the method call. printInfo() will display the employee
information. Arrays of name, year of joining, salary, address is created which will store the
values respectively of the three employees.

PROGRAM:

import java.util.Scanner;

class Employee
{
String[] name=new String[3];
String address[]=new String[3];
int yearofjoining[]=new int[3];
float salary[]=new float[3];
}public class Main {
public static void main(String[] args){
Scanner obj1=new Scanner(System.in);
Employee emp=new Employee();
int i;
for (i=0;i<3;i++){
System.out.println("\nFor employee" +(i+1));
System.out.print("\nEnter name: ");
emp.name[i]=obj1.next();
System.out.print("Enter the year of joining: ");
emp.yearofjoining[i]=obj1.nextInt();
System.out.print("Enter the salary: ");
emp.salary[i]=obj1.nextFloat();
System.out.print("Enter address: ");
emp.address[i]=obj1.next();
}
}
}
OUTPUT:
CONCLUSION: In this way, we could implement a program that would print the information
(name, year of joining, salary, address) of three employees. Hence, information of three
employees is displayed. We learnt the concepts of arrays, ‘for’ loop, methods, use of ‘this’
keyword.

You might also like