Run Rate ( java program)
A vital parameter in the game of Cricket is Run rate. It is vital in the way that it helps the opposition team to plan a chase. Lets write a program to help the teams to compute run rate.
Run rate is the statistical method used to compute the average runs per over that a team scores.
An over is made up of six balls. The runrate can be computed as, Runrate = ( Total runs scored / Total overs faced ).
Run Rate required is the rate at which the chasing team should score their runs to win the match.
Write a program to compute current run rate and the run rate required after a particular over.
Create a main class with the name "Main".
Input and Output Format:
All the inputs are Integer numbers and the Output runrate is a Floating Point number.
[All text in bold corresponds to input and the rest corresponds to output]
Sample Input and Output :
Enter total number of overs :
50
Enter Target Runs :
300
Enter overs bowled :
10
Enter Runs scored :
50
Current Run Rate : 5.0
Run Rate required after 10 overs : 6.25
Answers
Solution:
The given code is written in Java.
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int overs, runs, overs_bowled, run_scored;
double current_runrate, next_runrate;
System.out.print("Enter total number of overs: ");
overs = sc.nextInt();
System.out.print("Enter target runs: ");
runs = sc.nextInt();
System.out.print("Enter overs bowled: ");
overs_bowled = sc.nextInt();
System.out.print("Enter runs scored: ");
run_scored = sc.nextInt();
sc.close();
current_runrate = run_scored / (double)overs_bowled;
System.out.println("Current run rate: " + current_runrate);
overs -= overs_bowled;
runs -= run_scored;
next_runrate = runs / (double)overs;
System.out.println("Run rate required after " + overs_bowled + " overs: " + next_runrate);
}
}
Steps:
- Accept the total number of overs.
- Accept the target runs.
- Accept the number of overs bowled till now.
- Accept the runs scored till now.
- Divide the runs scored by overs bowled till now to get the current run rate. Display the result on screen.
- Subtract overs bowled from total overs. Result is the remaining overs.
- Subtract runs scored till now from total runs. Result is the remaining runs.
- Divide the runs remaining by total overs remaining. Result is the next run rate. Display it on screen.
Refer to the attachment for output.