Skip to content

Commit 3ed44cb

Browse files
committed
Team (IPA-35)
1 parent ac5778d commit 3ed44cb

2 files changed

Lines changed: 132 additions & 0 deletions

File tree

IPA28.java

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.util.Scanner;
2+
public class IPA28 {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
int n = sc.nextInt();sc.nextLine();
6+
Team[] t = new Team[n];
7+
for (int i = 0; i < t.length; i++) {
8+
int a = sc.nextInt();sc.nextLine();
9+
String b = sc.nextLine();
10+
String c = sc.nextLine();
11+
int d = sc.nextInt();
12+
13+
t[i] = new Team(a,b,c,d);
14+
}
15+
int r = sc.nextInt();sc.nextLine();
16+
String con = sc.nextLine();
17+
Team ans = findPlayer(t,r,con);
18+
if(ans!=null)
19+
{
20+
System.out.println(ans.gettId());
21+
System.out.println(ans.gettName());
22+
System.out.println(ans.gettCountry());
23+
System.out.println(ans.gettRun());
24+
}
25+
else
26+
{
27+
System.out.println("No team is found from the given country and run");
28+
}
29+
}
30+
public static Team findPlayer(Team[] t, int r, String c)
31+
{
32+
for (int i = 0; i < t.length; i++) {
33+
if(t[i].gettCountry().equalsIgnoreCase(c) && t[i].gettRun()>r)
34+
{
35+
return t[i];
36+
}
37+
}
38+
return null;
39+
}
40+
}
41+
class Team
42+
{
43+
private int tId;
44+
private String tName;
45+
private String tCountry;
46+
private int tRun;
47+
public Team(int tId, String tName, String tCountry, int tRun) {
48+
this.tId = tId;
49+
this.tName = tName;
50+
this.tCountry = tCountry;
51+
this.tRun = tRun;
52+
}
53+
public int gettId() {
54+
return tId;
55+
}
56+
public void settId(int tId) {
57+
this.tId = tId;
58+
}
59+
public String gettName() {
60+
return tName;
61+
}
62+
public void settName(String tName) {
63+
this.tName = tName;
64+
}
65+
public String gettCountry() {
66+
return tCountry;
67+
}
68+
public void settCountry(String tCountry) {
69+
this.tCountry = tCountry;
70+
}
71+
public int gettRun() {
72+
return tRun;
73+
}
74+
public void settRun(int tRun) {
75+
this.tRun = tRun;
76+
}
77+
78+
}

IPA28.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
Create class Team with below attributes:
2+
3+
tId - int
4+
tName - String
5+
tCountry - String
6+
tRun - int
7+
8+
The above attributes should be private.Write Getter and Setter and parametrized constructor as required.
9+
10+
Create class Solution with main method.
11+
12+
Implement One static method-
13+
14+
● findPlayer
15+
16+
findPlayer in the solution class.
17+
This method will take array of Team objects, int paramater run and String country and returns the Team object where taken
18+
country is matched with the country of team object and team run is greater than the taken run.
19+
20+
Write code to perform following tasks:
21+
22+
1. In main mehod, take 1st input as integer parameter which shows the number of team object.
23+
2. Take necessary input variable and call findPlayer.
24+
3. All searches should be case insensitive.
25+
26+
For this method- The main method should print the team object. As if the returned value is not null,
27+
or it should print "No team is found from the given country and run".
28+
29+
Input
30+
------------------
31+
3
32+
1
33+
Arijit
34+
India
35+
43
36+
2
37+
Doremon
38+
China
39+
40
40+
3
41+
Donal
42+
England
43+
32
44+
35
45+
China
46+
47+
48+
49+
Output
50+
--------------
51+
2
52+
Doremon
53+
China
54+
40

0 commit comments

Comments
 (0)