Menu
Question Index
...


Write a program to get the top scorer in a cricket match. Assume that there are no extras like wides, no-balls etc.

Input (List, List) Output (BatsmanSummary)
[2:false, 1:false, 0:false, 0:false, 1:false, 4:false, 0:false, 0:false, 1:false, 3:false, 4:false, 1:false, 0:true, 1:false, 0:true, 6:false, 4:false, 6:false]
[Gambhir, Rahane, Kohli, Yuvraj, Raina, Dhoni, Jadeja, Ashwin, Sharma, Kumar, Ahmed]
Yuvraj 16*
[0:false, 0:false, 4:false, 4:false, 1:false, 4:false, 0:true, 0:false, 0:true, 6:false, 4:false, 6:false, 0:true, 1:false, 0:true, 6:false, 4:false, 6:false]
[Gambhir, Rahane, Kohli, Yuvraj, Raina, Dhoni, Jadeja, Ashwin, Sharma, Kumar, Ahmed]
Dhoni 16*
[0:false, 0:false, 0:false, 0:true, 6:false, 6:false, 0:true, 4:false, 4:false, 4:false, 4:false, 0:true]
[Gambhir, Rahane, Kohli, Yuvraj, Raina, Dhoni, Jadeja, Ashwin, Sharma, Kumar, Ahmed]
Yuvraj 16

class GetTopScorer

{    public static void main(String s[])
    {
        List ballActivities = new ArrayList();
        ballActivities.add(new BallActivity(0, false));
        ballActivities.add(new BallActivity(0, false));
        ballActivities.add(new BallActivity(0, false));
        ballActivities.add(new BallActivity(0, true));
        ballActivities.add(new BallActivity(2, false));
        ballActivities.add(new BallActivity(1, false));
        ballActivities.add(new BallActivity(0, true));
        ballActivities.add(new BallActivity(3, false));
        ballActivities.add(new BallActivity(4, false));
        ballActivities.add(new BallActivity(2, false));
        ballActivities.add(new BallActivity(4, false));
        ballActivities.add(new BallActivity(0, true));
        List batsmanOrder = new ArrayList();
        batsmanOrder.add("Gambhir");
        batsmanOrder.add("Rahane");
        batsmanOrder.add("Kohli");
        batsmanOrder.add("Yuvraj");
        batsmanOrder.add("Raina");
        batsmanOrder.add("Dhoni");
        batsmanOrder.add("Jadeja");
        batsmanOrder.add("Ashwin");
        batsmanOrder.add("Sharma");
        batsmanOrder.add("Kumar");
        batsmanOrder.add("Ahmed");
        BatsmanSummary batsmanSummary = getTopScorer(ballActivities, batsmanOrder);
        System.out.println("The top scorer is : " + batsmanSummary);

    }


public static BatsmanSummary getTopScorer(List<BallActivity> ballActivities, List<String> batsmen) {
//Write code here to get the top scorer in the match.
}

//Write code here if you want to create any additional methods.
}
class BallActivity {

int runs;
boolean wicket;

public BallActivity(int runs, boolean wicket) {
this.runs = runs;
this.wicket = wicket;
}

@Override
public String toString() {
return runs + ":" + wicket;
}
}

class BatsmanSummary {

String name;
int runs;
boolean out;

public BatsmanSummary(String name, int runs, boolean out) {
this.name = name;
this.runs = runs;
this.out = out;
}

public BatsmanSummary(String name, boolean out) {
this.name = name;
runs = 0;
this.out = out;
}

@Override
public String toString() {
return name + " " + runs + (out ? "" : "*");
}

@Override
public boolean equals(Object obj) {
BatsmanSummary otherBatsmanSummary = (BatsmanSummary) obj;
return name.equals(otherBatsmanSummary.name) && runs == otherBatsmanSummary.runs && out == otherBatsmanSummary.out;
}
}

Doubts

Problems

Topic: Collection Framework In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App