Menu
Question Index
...


Write a program to calculate the number of matches, total wickets, strike rate, best, average, 5 wicket innings (5WI) and economy rate of a bowler. The strike rate is number of balls per wicket. The average is number of runs per wicket. The economy rate is number of runs per number of overs. Number of overs is nothing but number of balls divided by 6. Assume that there are no extras like wides, no-balls etc.

Input (List) Output (BowlerInfo)
[12:30:4, 2:12:2, 86:60:0, 23:24:1, 54:60:3, 26:46:5, 22:28:5, 4:24:2, 75:60:0, 3:15:2, 32:43:0, 28:47:2, 0:24:2, 76:60:0] [matches=14, totalWickets=28, best=5/22, strikeRate=19.04, average=15.82, 5WI=2, economyRate=5.03]
[34:60:2, 37:48:0, 48:60:3, 20:60:0, 15:30:2, 4:19:3, 40:60:4, 32:54:2, 45:58:3, 21:46:3, 78:60:0, 57:47:2] [matches=12, totalWickets=24, best=4/40, strikeRate=25.08, average=17.96, 5WI=0, economyRate=4.31]

class GetBowlerInfo

{    public static void main(String s[])
    {
        List ininngsActivity = new ArrayList();
        ininngsActivity.add(new IninngsActivity(45, 60, 3));
        ininngsActivity.add(new IninngsActivity(60, 48, 2));
        ininngsActivity.add(new IninngsActivity(23, 60, 1));
        ininngsActivity.add(new IninngsActivity(34, 24, 0));
        ininngsActivity.add(new IninngsActivity(12, 45, 5));
        ininngsActivity.add(new IninngsActivity(78, 60, 0));
        ininngsActivity.add(new IninngsActivity(34, 54, 1));
        ininngsActivity.add(new IninngsActivity(32, 60, 5));
        ininngsActivity.add(new IninngsActivity(12, 36, 0));
        System.out.println("The Bowler info is : " + getBowlerInfo(ininngsActivity));

    }


private static BowlerInfo getBowlerInfo(List<IninngsActivity> ininngsActivities) {
//Write code here to calculate the number of matches, total wickets, strike rate, best, average, 5 wicket innings (5WI) and economy rate of a bowler.
}
}
class IninngsActivity {

int runs;
int balls;
int wickets;

public IninngsActivity(int runs, int balls, int wickets) {
this.runs = runs;
this.balls = balls;
this.wickets = wickets;
}

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

class BowlerInfo {

int matches;
int totalWickets;
double strikeRate;
double average;
String best;
int fiveWickets;
double economyRate;

public BowlerInfo(int matches, int totalWickets, String best, int fiveWickets, double economyRate, double strikeRate, double average) {
this.matches = matches;
this.totalWickets = totalWickets;
this.best = best;
this.fiveWickets = fiveWickets;
this.economyRate = economyRate;
this.strikeRate = strikeRate;
this.average = average;
}

@Override
public boolean equals(Object obj) {
BowlerInfo otherInfo = ((BowlerInfo) obj);
return matches == otherInfo.matches && totalWickets == otherInfo.totalWickets && strikeRate == otherInfo.strikeRate && average == otherInfo.average && best.equals(otherInfo.best) && fiveWickets == otherInfo.fiveWickets && economyRate == otherInfo.economyRate;
}

@Override
public String toString() {
DecimalFormat decimalFormat = new DecimalFormat("##0.00");
return "[matches=" + matches + ", totalWickets=" + totalWickets + ", best=" + best + ", strikeRate=" + decimalFormat.format(strikeRate) + ", average=" + decimalFormat.format(average) + ", 5WI=" + fiveWickets + ", economyRate=" + decimalFormat.format(economyRate) + "]";
}
}

Doubts

Problems

Topic: Java Formatting Numbers

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App