0% found this document useful (0 votes)
333 views

COMSCPBTech498771rObjrPr - Program On Array of Objects

Mr. John is the database administrator for the CGI Company. He maintains an employee database with information like ID, name, age, and salary for each employee. To access the records, he stores all employee data in a single table. The program defines an Employee class with attributes for each data field. An array of Employee objects is created to store multiple records, and a for loop iterates through the array to get data input from the user and output the stored details.

Uploaded by

Aneal Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
333 views

COMSCPBTech498771rObjrPr - Program On Array of Objects

Mr. John is the database administrator for the CGI Company. He maintains an employee database with information like ID, name, age, and salary for each employee. To access the records, he stores all employee data in a single table. The program defines an Employee class with attributes for each data field. An array of Employee objects is created to store multiple records, and a for loop iterates through the array to get data input from the user and output the stored details.

Uploaded by

Aneal Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program on Array of objects

Mr. John has joined the CGI Company as Database


Administrator and his major role is to maintain the Employee
database which includes Employee Id, Employee Name, Age
and Employee Salary. The criteria for maintaining is that he
needs to store all the records in one single table. How Mr. John
is going to access all the records which he has stored?

Solution:
import java.util.Scanner;

class Employee
{
int Id;
String Name;
int Age;
long Salary;

void GetData() // Defining GetData()


{

Scanner sc = new Scanner(System.in);

System.out.print("\n\tEnter Employee Id : ");


Id = sc.nextInt();

System.out.print("\n\tEnter Employee Name : ");


Name = sc.next();

System.out.print("\n\tEnter Employee Age : ");


Age = sc.nextInt();

System.out.print("\n\tEnter Employee Salary : ");


Salary = sc.nextLong();

void PutData() // Defining PutData()


{
System.out.print("\n\t" + Id + "\t" +Name + "\t" +Age + "\t"
+Salary);
}

public static void main(String args[])


{

Employee[] Emp = new Employee[3];


int i;

for(i=0;i<3;i++)
Emp[i] = new Employee(); // Allocating memory to each
object

for(i=0;i<3;i++)
{
System.out.print("\nEnter details of "+ (i+1) +" Employee\n");

Emp[i].GetData();
}

System.out.print("\nDetails of Employees\n");
for(i=0;i<3;i++)
Emp[i].PutData();

}}

You might also like