info@meritcampus.com    +91-85006-22255
...

Write a program to calculate batsman strike rate, highest score, average, number of half centuries, number of centuries, number of matches. The strike rate is number of runs obtained per balls faced. The average is calculated by dividing the total number of runs by the number of times the batsman got out.

Input (List) Output (BatsmanInfo)
[10:30:F, 24:12:T, 111:84:T, 155:184:F, 54:109:T, 48:122:T, 99:121:T, 98:58:T, 134:112:T, 78:151:F, 94:56:T, 82:47:T, 0:15:F, 12:25:T] [matches=14, totalScore=999, strikeRate=0.8872113676731794, average=99.9, halfCenturies=6, centuries=3, highestScore=155]
[121:90:T, 34:45:T, 44:92:T, 123:155:T, 32:45:F, 4:12:T, 2:3:T, 65:23:T, 67:32:T, 0:12:T, 13:6:T, 0:6:F] [matches=12, totalScore=505, strikeRate=0.9692898272552783, average=50.5, halfCenturies=2, centuries=2, highestScore=123]

``` class GetBatsmanInfo {    public static void main(String s[])    {        List ininngsActivity = new ArrayList();        ininngsActivity.add(new MatchIninngsActivity(120, 121, true));        ininngsActivity.add(new MatchIninngsActivity(100, 112, false));        ininngsActivity.add(new MatchIninngsActivity(0, 12, true));        ininngsActivity.add(new MatchIninngsActivity(12, 25, false));        ininngsActivity.add(new MatchIninngsActivity(112, 72, true));        ininngsActivity.add(new MatchIninngsActivity(54, 23, true));        ininngsActivity.add(new MatchIninngsActivity(0, 12, true));        ininngsActivity.add(new MatchIninngsActivity(56, 111, false));        ininngsActivity.add(new MatchIninngsActivity(23, 58, true));        System.out.println("The Batsman info is : " + getBatsmanInfo(ininngsActivity));    } private static BatsmanInfo getBatsmanInfo(List<MatchIninngsActivity> ininngsActivities) { //Write code here to calculate batsman strike rate, highest score, average, number of half centuries, number of centuries, number of matches. } } class MatchIninngsActivity { int runs; int balls; boolean out; public MatchIninngsActivity(int runs, int balls, boolean out) { this.runs = runs; this.balls = balls; this.out = out; } @Override public String toString() { return runs + ":" + balls; } } class BatsmanInfo { int matches; int totalScore; double strikeRate; double average; int halfCenturies; int centuries; int highestScore; public BatsmanInfo(int matches, int totalScore, int halfCenturies, int centuries, int highestScore, double strikeRate, double average) { this.matches = matches; this.totalScore = totalScore; this.halfCenturies = halfCenturies; this.centuries = centuries; this.highestScore = highestScore; this.strikeRate = strikeRate; this.average = average; } @Override public boolean equals(Object obj) { BatsmanInfo otherInfo = ((BatsmanInfo) obj); return matches == otherInfo.matches && totalScore == otherInfo.totalScore && strikeRate == otherInfo.strikeRate && average == otherInfo.average && halfCenturies == otherInfo.halfCenturies && centuries == otherInfo.centuries && highestScore == otherInfo.highestScore; } @Override public String toString() { return "[matches=" + matches + ", totalScore=" + totalScore + ", strikeRate=" + strikeRate + ", average=" + average + ", halfCenturies=" + halfCenturies + ", centuries=" + centuries + ", highestScore=" + highestScore + "]"; } } ```

Topic: Java ArrayList

0
Wrong
Score more than 2 points