Question

In: Computer Science

Abdullah is a batsman who has played 10 matches in a local cricket club. Take user...

Abdullah is a batsman who has played 10 matches in a local cricket club. Take user input in a 2D array to store his score in first row and second row for balls he has faced in each match.

Calculate and display the strike rate (SR) of Mr. Abdullah in all 10 matches he has played.

SR=score/number of balls faced×100

Count and display the number of 50s and 100s he has score.

Solutions

Expert Solution

import java.util.*;
import java.io.*;
class Main
{
  public static void main(String args[]) throws Exception
  {
    //variable declaration
    int number_of_matches=10;
    int score=0,balls=0;
    int fifty_count=0,century_count=0;
    Scanner sc = new Scanner(System.in);//object of Scanner
    int[][] matches = new int[2][number_of_matches];//array initialization
    System.out.println("Enter scores and number of ball face by Abdullah ");
    //for loop to take user input for scores and balls faced
    for(int i=0;i<2;i++)
    {
      if((i+1)==1){
        System.out.println("Enter scores in first row");
        for(int j=0;j<number_of_matches;j++)
        {
          matches[i][j] = sc.nextInt();
        }
      }
      else if((i+1)==2)
      {
        System.out.println("Enter number balls faced in second row");
        for(int j=0;j<number_of_matches;j++)
        {
          matches[i][j] = sc.nextInt();
        }
      }
      
    }
    //for loop to print the scores and balls faced
    for(int i=0;i<2;++i)
    {
      if((i+1)==1)
      {
        System.out.println("Scores:");
      
      for(int j=0;j<number_of_matches;j++)
      {
        System.out.print(matches[i][j]+"\t");
      
      }
      }
      
      else if((i+1)==2)
      {
      System.out.println("\nNumber balls faced:");
      for(int j=0;j<number_of_matches;j++)
      {
         System.out.print(matches[i][j]+"\t");
      }
      }
    }
    //for loop to calculate Total score and total number of balls faced
    for(int i=0;i<2;i++)
    {
      if((i+1)==1)
      {
        for(int j=0;j<number_of_matches;j++)
        {
          score += matches[i][j]; //total score
        }
      }
      else if((i+1)==2)
      {
        for(int j=0;j<number_of_matches;j++)
        {
          balls += matches[i][j]; //total balls faced
        }
      }
    }
    //prints total score and total number of balls faced
    System.out.println("\nTotal Score:"+score);
    System.out.println("Total Balls faced:"+balls);
    //calculate the strike rate
    double Strike_rate = (score/balls)*100;
    //for loop to count number of centuries and number of half centuries
    for(int i=0;i<1;i++)
    {
      for(int j=0;j<number_of_matches;j++){
      if(matches[i][j]>=50 && matches[i][j]<100)
      {
        fifty_count++;
      }
      else if(matches[i][j]>=100 && matches[i][j]<200)
      {
        century_count++;
      }
    }
    }
    //output Strike_rate,fifty_count and century_count 
    System.out.println("Strike rate of Abdullah: "+Strike_rate);
    System.out.println("Number of half century scored by Abdullah is: "+fifty_count);
    System.out.println("Number of centuries scored by Abdullah is: "+century_count);

}}

Output::

If any queries please comment and do like


Related Solutions

Mohammed Abdullah is a trade supplier who has been approached by ABC Builders who are requesting...
Mohammed Abdullah is a trade supplier who has been approached by ABC Builders who are requesting credit terms for the first time. Their managing director has provided Mohammed Abdullah with the following extracts from the final accounts for the past two years and Mohammed Abdullah has approached you for advice. Details 2018 (OMR) 2019 (OMR) Purchases 120.000 250,000 Purchase returns 20,000 30,000 Sales turnover 800,000 850,000 Cost of goods sold 350,000 240,000 Buildings 148,000 126,000 Inventory 25,000 68,000 Operating expenses...
Mark has done the accounts for his local basketball club for a number of years. You...
Mark has done the accounts for his local basketball club for a number of years. You joined the club in the last year and as you have studied some accounting Mark has asked you to help him with the accounts. You note that when doing a bank reconciliation Mark changes the accounts of the basketball club so that they show the same month end cash balance as the bank statement even though there are outstanding deposits and cheques. Mark believes...
3- Use Mintzberg's Managerial Roles to analyze the managerial roles played by an entrepreneur who has...
3- Use Mintzberg's Managerial Roles to analyze the managerial roles played by an entrepreneur who has just established a start-up. 4-What is the Systems Approach of Management? Do you think this approach is applicable in today's management practice? Why and How? Use examples to illustrate your point. 9-Describe an effective culture for (a) a relatively stable environment and (b) a dynamic environment. Explain your choices and give one example (a company you know) for each situation.
CodeDesk Inc matches programmers with freelance jobs. It has 30 employees who staff its online chat...
CodeDesk Inc matches programmers with freelance jobs. It has 30 employees who staff its online chat room. It receives, on average, 240 chat requests per hour, and the average chat session takes 5 minutes to complete ( i. e., from start to finish). On average, how many chat sessions are active (i.e., started but not completed)?
Develop a python program that prompts the user to take up the quiz (which has choices)...
Develop a python program that prompts the user to take up the quiz (which has choices) with limited attempts and limited time. Suppose if the user answered wrong then they have to get numer of attempts(limited) Quiz should have questions on General knowldge & multiple choices for those questions
A club has 50 members of which 20 are freshmen, 15 are sophomores, 10 are juniors...
A club has 50 members of which 20 are freshmen, 15 are sophomores, 10 are juniors and 5 are seniors. a) How many ways are there to select a president, a senior vice president, and a vice president if they can not be from the same class? b) How many ways are there to select one president, and two vice presidents if they can not be from the same class?
Develop a python program to ask the user to take up the quiz(General knowledge) which has...
Develop a python program to ask the user to take up the quiz(General knowledge) which has around 4 or 5 questions & choices for those questions. For each question user should have 2 or 3 attempts suppose if they are wrong. Develop the in such a manner to add few more questions and remove some questions.
Why is it Bruno, and not Angela, who has the power to make a take-it-or-leave-it offer?
EXERCISE 5.8 TAKE IT OR LEAVE IT?Why is it Bruno, and not Angela, who has the power to make a take-it-or-leave-it offer? Can you imagine a situation in which the farmer, not the landowner, might have this power?
Q2) A drug manufacturer claims that fewer than 10% of patients who take its new drug...
Q2) A drug manufacturer claims that fewer than 10% of patients who take its new drug for treating Alzheimer’s disease will experience nausea. In a random sample of 500 patients, 47 experienced nausea. Perform a significance test at the 5% significance level to test this claim. (a) State the null and alternative hypothesis. (b) Calculate the test statistic. (c) Calculate the p-value. Round to 4 decimal places (d) Make a decision at the 0. 05 significance level to reject Ho...
if you take a rock the has a mass of 1 pound 10 ounces, and you...
if you take a rock the has a mass of 1 pound 10 ounces, and you throw it with a velocity of 75 mph what would the wavelength be?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT