Skip to content

Commit

Permalink
Associate (IPA-35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arijit-SE committed Feb 26, 2023
1 parent b43f16e commit 1ad4408
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 0 deletions.
86 changes: 86 additions & 0 deletions IPA22/IPA22.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package IPA22;
import java.util.*;
public class IPA22
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Associate[] as = new Associate[5];
for (int i = 0; i < as.length; i++)
{
int a = sc.nextInt();sc.nextLine();
String b = sc.nextLine();
String c = sc.nextLine();
int d = sc.nextInt();sc.nextLine();

as[i] = new Associate(a, b, c, d);
}
String st = sc.nextLine();
Associate[] ans = associatesForGivenTechnology(as,st);
if(ans!=null)
{
for (int i = 0; i < ans.length; i++) {
System.out.println(ans[i].getId());
}
}
}
public static Associate[] associatesForGivenTechnology(Associate[] a, String s)
{
Associate[] arr = new Associate[0];
for (int i = 0; i < a.length; i++) {
if(a[i].getTech().equalsIgnoreCase(s) && a[i].getYear()%5==0)
{
arr = Arrays.copyOf(arr,arr.length+1);
arr[arr.length-1]=a[i];
}
}
if(arr.length>0)
{
return arr;
}
else
{
return null;
}
}
}

class Associate
{
private int id;
private String name;
private String tech;
private int year;

public Associate(int id, String name, String tech, int year) {
this.id = id;
this.name = name;
this.tech = tech;
this.year = year;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTech() {
return tech;
}
public void setTech(String tech) {
this.tech = tech;
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}


}
45 changes: 45 additions & 0 deletions IPA22/IPA22.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Create class Associate with below attributes:
id - int
name - String
technology - String
experienceInYears - int

Create class Solution and implement static method "associatesForGivenTechnology" in the Solution class.
This method will take array of Associate objects and a searchTechnology String as parameters.
And will return another array of Associate objects where the searchTechnology String matches with the original array of
Associate object's technology attribute (case insensitive search) and experienceInYears attribute should be multiples of 5.

Write necessary getters and setters.

Before calling "associatesForGivenTechnology" method in the main method, read values for five associate objects referring
the attributes in above sequence along with a String searchTechnology.
Then call the "associatesForGivenTechnology" method and write the logic to print the id's in the main method.

Input
-----------------
101
Alex
Java
15
102
Albert
Unix
20
103
Alferd
Testing
13
104
Alfa
Java
15
105
Almas
Java
29
Java

Output
------------------
101
104

0 comments on commit 1ad4408

Please sign in to comment.