0% found this document useful (0 votes)
4 views11 pages

Java Salary Management System

The document contains Java code for managing a list of associates, calculating their salaries, and performing various operations such as finding the maximum and minimum salaries, calculating the sum and average of salaries, and searching for an associate by name. It includes the definition of an Associate class with attributes for id, name, and salary, along with methods to manipulate and retrieve data from an array of Associate objects. Additionally, there are examples of working with primitive arrays, including methods for summing, averaging, finding maximum and minimum values, and searching for elements.

Uploaded by

bhuvaneshmvbk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views11 pages

Java Salary Management System

The document contains Java code for managing a list of associates, calculating their salaries, and performing various operations such as finding the maximum and minimum salaries, calculating the sum and average of salaries, and searching for an associate by name. It includes the definition of an Associate class with attributes for id, name, and salary, along with methods to manipulate and retrieve data from an array of Associate objects. Additionally, there are examples of working with primitive arrays, including methods for summing, averaging, finding maximum and minimum values, and searching for elements.

Uploaded by

bhuvaneshmvbk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;
public class Solution {

public static void main(String[] args) {


// TODO Auto-generated method stub

/*Associate a1=new
Associate(1,"Srinidhi",35000);
Associate a2=new Associate(2,"Hismath",54000);
Associate a3=new Associate(3,"Ramya",73000);
Associate A[]=new Associate[]{a1,a2,a3};*/
//sum of salaries
Scanner sc=new Scanner([Link]);
int n=[Link]();
Associate A[]=new Associate[n];
for(int i=0;i<[Link];i++)
{//use extra [Link]() between numeric
input and string
int id=[Link]();
[Link]();
String name=[Link]();
double salary=[Link]();
A[i]=new Associate(id,name,salary);
//i=0 Associate (1,"srinidhi",35000) =A[0]
}
[Link]();
String sname=[Link]();

double sum=SumofSalaries(A);
[Link]("Sum = "+sum);
//Avg of salaries
double avg=AvgOfSalaries(A);
[Link]("avg = "+avg);
//max of salaries
Associate maxSal=findAssociateByMaxSalary(A);
[Link]("Max salary result :"+
[Link]() +" id-"+[Link]()+" Salary
-"+[Link]());
//min of salaries
Associate minSal=findAssociateByminSalary(A);
[Link]("min salary result :"+
[Link]() +" id-"+[Link]()+" Salary
-"+[Link]());

//search for Hismath


Associate
searchres=searchAssociateByName(A,sname);
if(searchres==null)
{
[Link]("not found");
}
else{
[Link]("Search result
"+[Link]()+ " "+[Link]()+"
"+[Link]());
}

}//main closing brace


public static double SumofSalaries(Associate[] A)
{
double sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+A[i].getSalary();
}
/*for(Associate i:A )
{
sum=sum+[Link]();
}*/
return sum;

}
public static double AvgOfSalaries(Associate[] A)
{
double avg=0,sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+A[i].getSalary();
}
avg=sum/[Link];
return avg;
}
public static Associate
findAssociateByMaxSalary(Associate[] A)
{
Associate maxobj=null;
double tempmax=A[0].getSalary();
//tempmax=35000 i=1 tempmax=54000 i=2
tempmax=73000
for(int i=0;i<[Link];i++)
{
if(A[i].getSalary()>tempmax)
{

tempmax=A[i].getSalary();
maxobj=A[i];
}
}
return maxobj;

public static Associate


findAssociateByminSalary(Associate[] A)
{
Associate minobj=null;
double tempmin=A[0].getSalary();
//
for(int i=0;i<[Link];i++)
{
if(A[i].getSalary()<=tempmin)
{
tempmin=A[i].getSalary();
minobj=A[i];
}
}
return minobj;

public static Associate


searchAssociateByName(Associate[] A, String sname)
{
Associate searchobj=null;
for(int i=0;i<[Link];i++)
{
if(A[i].getName().equalsIgnoreCase(sname))
{
searchobj=A[i];
}
}
return searchobj;
}

}
//Associate class

public class Associate {


private int id;
private String name;
private double salary;
public Associate(int id, String name, double
salary) {

[Link] = id;
[Link] = name;
[Link] = salary;
}
public int getId() {
return id;
}
public void setId(int id) {
[Link] = id;
}
public String getName() {
return name;
}
public void setName(String name) {
[Link] = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
[Link] = salary;
}

primitive arrays intial code

public class Arraysp {

public static void main(String[] args) {


// TODO Auto-generated method stub
int arr[]=new int[]{56,3,6,9,1};
/*[Link]([Link]);
//max, min,sum,avg,total,count,search
int sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+arr[i];
//i=0 sum=0+arr[0]=0+1=1
//i=1 sum=1+3=4
}
[Link]("Sum of array elements =
"+sum);
[Link]("Avg of array elements = "+
(double)sum/[Link]);
//sum of array elements >5
sum=0;int c=0;
for(int i=0;i<[Link];i++)
{
if(arr[i]>5){
sum=sum+arr[i];
c++;}
//i=0 sum=0+arr[0]=0+1=1
//i=1 sum=1+3=4
}
[Link]("Sum of array elements >5
= "+sum);
[Link]("Avg of array elements >5
= "+(double)sum/c);
*/
/* max method
int max=arr[0];//max=1
for(int i=0;i<[Link];i++)
{//{1,3,6,9}
//i=0 1>1 false max=1
//i=1 3>1 true max=3
//i=2 6>3 true max=6
//i=3 9>6 true max=9

if(arr[i]>max)
{
max=arr[i];

}
}
[Link](max);
*/
/*int min=arr[0];//min=56
for(int i=0;i<[Link];i++)
{//{56,3,6,9,1}
//i=0 56<56 false min 56
//i=1 3<56 true min=3
//i=2 6<3 false min=3
//i=3 9<3 false min=3
//i=4 1<3 true min=1

if(arr[i]<min)
{
min=arr[i];

}
}
[Link](min);*/
// search for an int 6 and get it's index
/*int index=-1;
for(int i=0;i<[Link];i++)
{
if(arr[i]==37)
{
index=i;
break;
}

}
if(index==-1)
{
[Link]("not found");
}
else{
[Link](index);}*/

// calling and printing methods


int sumof=SumofElements(arr);
[Link]("sum of array elements
"+sumof);
}//main closing brace

public static int SumofElements(int[] arr)


{
int sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+arr[i];
}
return sum;

}
}

// with methods

import [Link].*;
public class Arraysp {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner([Link]);
int n=[Link]();
int arr[]=new int[n];
for(int i=0;i<[Link];i++)
{
arr[i]=[Link]();
}
int s=[Link]();

// calling and printing methods


int sumof=SumofElements(arr);
[Link]("sum of array elements
"+sumof);
[Link](SumofElements(arr));
//Avg of elements
double avg=AvgofElements(arr);
[Link]("Average = "+avg);
//max
int max=MaxofElements(arr);
[Link]("max of elements = "+max);
//min
int min=MinofElements(arr);
[Link]("min of elements = "+min);
//search
int index=SearchElement(arr,s);
[Link]("index of 99 = "+index);

}//main closing brace

public static int SumofElements(int[] arr)


{
int sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+arr[i];
}
return sum;

}
public static double AvgofElements(int[] arr)
{
double sum=0;
for(int i=0;i<[Link];i++)
{
sum=sum+arr[i];
}
return sum/[Link];

}
public static int MaxofElements(int[] arr)
{
int max=arr[0];
for(int i=0;i<[Link];i++)
{

if(arr[i]>max)
{
max=arr[i];

}
}
return max;
}
public static int MinofElements(int[] arr)
{
int min=arr[0];
for(int i=0;i<[Link];i++)
{

if(arr[i]<min)
{
min=arr[i];

}
}
return min;
}

public static int SearchElement(int[] arr, int s)


{
int index=-1;
for(int i=0;i<[Link];i++)
{
if(arr[i]==s)
{
index=i;

}
}
return index;
}

You might also like