0% found this document useful (0 votes)
33 views3 pages

IPA26

Uploaded by

Aayush Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views3 pages

IPA26

Uploaded by

Aayush Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import java.util.

*;

class Player2 {
private int id;
private String name;
private int iccRank;
private int matchesPlayed;
private int runsScored;

public void setId(int id)


{
this.id = id;
}
public void setName(String name)
{
this.name = name;
}
public void setRank(int iccRank)
{
this.iccRank = iccRank;
}
public void setPlayed(int matchesPlayed)
{
this.matchesPlayed = matchesPlayed;
}
public void setScored(int runsScored)
{
this.runsScored = runsScored;
}

public int getId()


{
return id;
}
public String getName()
{
return name;
}
public int getRank()
{
return iccRank;
}
public int getPlayed()
{
return matchesPlayed;
}
public int getScored()
{
return runsScored;
}

public Player2(int id, String name, int iccRank, int matchesPlayed, int
runsScored)
{
this.id = id;
this.name = name;
this.iccRank = iccRank;
this.matchesPlayed = matchesPlayed;
this.runsScored = runsScored;
}
}

public class Main


{
public static double[] findAverageOfRuns(Player2 []p, int target_played)
{
boolean found = false;
ArrayList<Double> list = new ArrayList<Double>();

for(int i=0;i<p.length;i++)
{
if(p[i].getPlayed() >= target_played && p[i].getPlayed() > 0)
{
found = true;
double avg = (double)p[i].getScored()/ p[i].getPlayed();
list.add(avg);
}
}

double []result = new double[list.size()];


for(int i=0;i<list.size();i++)
{
result[i] = list.get(i);
}
if(found)
{
return result;
}
else
{
return new double[0];
}
}

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

int n = sc.nextInt();
Player2 []p = new Player2[n];

for(int i=0;i<n;i++)
{
int id = sc.nextInt();
sc.nextLine();
String name = sc.nextLine();
int iccRank = sc.nextInt();
int matchesPlayed = sc.nextInt();
int runsScored = sc.nextInt();

p[i] = new Player2(id, name, iccRank, matchesPlayed, runsScored);


}

int target_played = sc.nextInt();

double []ans1 = findAverageOfRuns(p, target_played);


if(ans1.length != 0)
{
for(int i=0;i<ans1.length;i++)
{
if(ans1[i] >= 80 && ans1[i] <= 100)
{
System.out.println("Grade A");
}
else if(ans1[i] >= 50 && ans1[i] <= 79)
{
System.out.println("Grade B");
}
else
{
System.out.println("Grade C");
}
}
}
else
{
System.out.println("No such player found");
}
}
}

You might also like