Skip to content

Commit 09f0982

Browse files
committed
Player2 (IPA-35)
1 parent 18a63f4 commit 09f0982

2 files changed

Lines changed: 150 additions & 35 deletions

File tree

IPA26.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import java.util.*;
2+
public class IPA26 {
3+
public static void main(String[] args) {
4+
Scanner sc = new Scanner(System.in);
5+
Player2[] pl = new Player2[4];
6+
for(int i=0; i<4; i++)
7+
{
8+
int a = sc.nextInt();sc.nextLine();
9+
String b = sc.nextLine();
10+
int c = sc.nextInt();sc.nextLine();
11+
int d = sc.nextInt();sc.nextLine();
12+
int e = sc.nextInt();sc.nextLine();
13+
14+
pl[i] = new Player2(a,b,c,d,e);
15+
}
16+
int target = sc.nextInt();sc.nextLine();
17+
double[] ans = findAverageOfRuns(pl,target);
18+
if(ans!=null)
19+
{
20+
for (int i = 0; i < ans.length; i++) {
21+
if(ans[i]>=80 && ans[i]<=100)
22+
{
23+
System.out.println("Grade A");
24+
}
25+
else if(ans[i]>=50 && ans[i]<=79)
26+
{
27+
System.out.println("Grade B");
28+
}
29+
else
30+
{
31+
System.out.println("Grade C");
32+
}
33+
}
34+
}
35+
}
36+
public static double[] findAverageOfRuns(Player2[]p, int t)
37+
{
38+
double[] arr = new double[0];
39+
for(int i=0; i<p.length; i++)
40+
{
41+
if(t<=p[i].getMatch())
42+
{
43+
arr = Arrays.copyOf(arr, arr.length+1);
44+
arr[arr.length-1] = (p[i].getRun()/p[i].getMatch());
45+
}
46+
}
47+
if(arr.length>0)
48+
{
49+
return arr;
50+
}
51+
else
52+
{
53+
return null;
54+
}
55+
}
56+
}
57+
class Player2
58+
{
59+
private int id;
60+
private String name;
61+
private int rank, match, run;
62+
63+
public Player2(int id, String name, int rank, int match, int run)
64+
{
65+
this.id = id;
66+
this.name = name;
67+
this.rank = rank;
68+
this.match = match;
69+
this.run = run;
70+
}
71+
72+
public int getId() {
73+
return id;
74+
}
75+
76+
public void setId(int id) {
77+
this.id = id;
78+
}
79+
80+
public String getName() {
81+
return name;
82+
}
83+
84+
public void setName(String name) {
85+
this.name = name;
86+
}
87+
88+
public int getRank() {
89+
return rank;
90+
}
91+
92+
public void setRank(int rank) {
93+
this.rank = rank;
94+
}
95+
96+
public int getMatch() {
97+
return match;
98+
}
99+
100+
public void setMatch(int match) {
101+
this.match = match;
102+
}
103+
104+
public int getRun() {
105+
return run;
106+
}
107+
108+
public void setRun(int run) {
109+
this.run = run;
110+
}
111+
112+
113+
}

IPA26.txt

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
## Problem Statement
1+
Create class Player2 with below attributes:
22

3-
Create class Player with below attributes:
43
id - int
54
name - String
65
iccRank - int
@@ -9,39 +8,42 @@ runsScored - int
98

109
Create class Solution and implement static method "findAverageOfRuns" in the Solution class.
1110
This method will take array of Player objects and a target int as parameters.
12-
And will return another double array where the target int is lesser than or equal to the original array of Player object's matchesPlayed attribute and contains the average run scored by each player satisfying above condition.
11+
And will return another double array where the target int is lesser than or equal to the original array of Player object's
12+
matchesPlayed attribute and contains the average run scored by each player satisfying above condition.
1313

1414
Write necessary getters and setters.
1515

16-
Before calling "findAverageOfRuns" method in the main method, read values for four Player objects referring the attributes in above sequence along with a int target.
17-
Then call the "findAverageOfRuns" method and write logic in main method to print "Grade A",if the calculated averageRun value is 80 to 100. Else if the averageRun value is between 50 and 79 then print "Grade B". Else print "Grade C"
18-
19-
## Input
20-
21-
100
22-
Sachin
23-
5
24-
150
25-
13000
26-
101
27-
Sehwag
28-
4
29-
120
30-
10000
31-
103
32-
Dhoni
33-
7
34-
110
35-
7000
36-
104
37-
Kohli
38-
15
39-
57
40-
4400
41-
100
42-
43-
## Output
44-
45-
Grade A
46-
Grade A
47-
Grade B
16+
Before calling "findAverageOfRuns" method in the main method, read values for four Player objects referring the attributes
17+
in above sequence along with a int target.
18+
Then call the "findAverageOfRuns" method and write logic in main method to print "Grade A",if the calculated averageRun
19+
value is 80 to 100. Else if the averageRun value is between 50 and 79 then print "Grade B". Else print "Grade C".
20+
21+
Input
22+
------------------
23+
100
24+
Sachin
25+
5
26+
150
27+
13000
28+
101
29+
Sehwag
30+
4
31+
120
32+
10000
33+
103
34+
Dhoni
35+
7
36+
110
37+
7000
38+
104
39+
Kohli
40+
15
41+
57
42+
4400
43+
100
44+
45+
Output
46+
--------------------
47+
Grade A
48+
Grade A
49+
Grade B

0 commit comments

Comments
 (0)