Solution3

 package pone;

import java.util.*;

class Unit
{
private int unitId;
private String unitName;
private int budget;
private ArrayList<Employee> employ;

public Unit(int unitId,String unitName,int budget,ArrayList<Employee> employ)
{
this.unitId = unitId;
this.unitName = unitName;
this.budget = budget;
this.employ = employ;
}


public int getUnitId() {
return unitId;
}

public Unit setUnitId(int unitId) {
this.unitId = unitId;
return this;
}

public String getUnitName() {
return unitName;
}

public Unit setUnitName(String unitName) {
this.unitName = unitName;
return this;
}

public int getBudget() {
return budget;
}

public Unit setBudget(int budget) {
this.budget = budget;
return this;
}

public ArrayList<Employee> getEmploy() {
return employ;
}

public Unit setEmploy(ArrayList<Employee> employ) {
this.employ = employ;
return this;
}
}
class Employee
{
private int employeeId;
private String employeeName;
private int salary;

public Employee(int employeeId,String employeeName,int salary)
{
this.employeeId = employeeId;
this.employeeName = employeeName;
this.salary = salary;
}

public int getEmployeeId() {
return employeeId;
}

public Employee setEmployeeId(int employeeId) {
this.employeeId = employeeId;
return this;
}

public String getEmployeeName() {
return employeeName;
}

public Employee setEmployeeName(String employeeName) {
this.employeeName = employeeName;
return this;
}

public int getSalary() {
return salary;
}

public Employee setSalary(int salary) {
this.salary = salary;
return this;
}
}

public class Solution3
{
public static void task1(ArrayList<Unit> uni,String input1)
{
int count = 0;
int sum = 0;
for(Unit uu : uni)
{
for(Employee ee : uu.getEmploy())
{
if(ee.getEmployeeName().equalsIgnoreCase(input1))
{
sum = sum + ee.getSalary();
count++;
}
if(ee.getSalary()<0)
{
System.out.println("Invalid Salary: salary cannot be negative");
return;
}
}
}
if(count == 0)
{
System.out.println("No employee found");
}
else System.out.println(sum);

}

public static void task2(ArrayList<Unit> uni,int input2)
{
int count = 0;

ArrayList<String> ans = new ArrayList<>();
for(Unit uu : uni)
{
boolean added = false;
for(Employee ee : uu.getEmploy())
{
if(ee.getSalary()>input2)
{
if(!added)
{
ans.add(uu.getUnitName());
count++;
added = true;
}
}
}
}
if(count == 0)
{
System.out.println("No matching units found");
}
else
{
for(String ss : ans)
{
System.out.println(ss);
}
}
}
public static void main(String[] args)
{
Scanner xx = new Scanner(System.in);
ArrayList<Unit> uni = new ArrayList<>();
int n = xx.nextInt();xx.nextLine();
for(int i = 0; i < n; i++)
{
int unitId = xx.nextInt();xx.nextLine();
String unitName = xx.nextLine();
int budget = 0;
int m = xx.nextInt();xx.nextLine();
ArrayList<Employee> emp = new ArrayList<>();
for(int j = 0; j < m; j++)
{
int employeeId = xx.nextInt();xx.nextLine();
String employeeName = xx.nextLine();
int salary = xx.nextInt();xx.nextLine();
emp.add(new Employee(employeeId,employeeName,salary));
}
uni.add(new Unit(unitId,unitName,budget,emp));
}
String input1 = xx.nextLine();
int input2 = xx.nextInt();xx.nextLine();
task1(uni,input1);
task2(uni,input2);

}
}

/*3
1001
BFSI
2
101
Sagar
25000
102
Shalini
26000
1002
CMI
1
204
SagarS
30000
1003
BNTS
2
301
subhash
12000
302
saniya
25000*/

Comments

Popular posts from this blog

Restaurant

TimePass

UIUXFILES