-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |