Question

In: Computer Science

. The file contains information about baseball players in a fictitious league. Here is a sample...

  1. . The file contains information about baseball players in a fictitious league. Here is a sample of the data:

Janet Littleton,6,7,14

Frank Edbrooke,17,9,31

Robert Hovery,25,1,18

Thomas Bingham,21,8,2

Stephen Bruce,7,9,23

For each player it shows:

  1. Her name,
  2. How many doubles she hit,
  3. How many triples she hit,
  4. How many home runs she hit [End of Line]

For example, Janet Littleton hit 6 doubles, 7 triples and 14 home runs. Frank Edbrooke hit 17 doubles, 9 triples and 31 home runs.

Your job is to determine:

  1. How many players there are in the league, and
  2. which players hit more triples than doubles and hit more triples than home runs. There are five players who meet these criteria:

Solutions

Expert Solution

Let's first compile and see the output of all the baseball players:

Source Code in Java:

import java.io.*;  
import java.util.Scanner;  
public class BaseballPlayers  
{  
public static void main(String[] args) throws Exception  
{  
Scanner sc = new Scanner(new File("/home/rohit/Desktop/baseballplayers.csv"));  
sc.useDelimiter(",");   
while (sc.hasNext()) 
{  
System.out.print(sc.next()); 
}   
sc.close(); 
}  
}  

Note: Change the path of the file in your case.

Screenshots for additional help:

Now according to the question, you need to find the number of baseball players which means you can simply return the count of how many players are there in the file or list. Here is the program for that:

import java.io.*;  
import java.util.Scanner;  
public class CountBaseballPlayers{
    public static long countLineBufferedReader(File file) {

     long lines = 0;
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
        while (reader.readLine() != null) lines++;
     } catch (IOException e) {
        e.printStackTrace();
     }
    return lines;

    }   
    public static void main(String[] args){
        File file = new File("/home/rohit/Desktop/baseballplayers.csv");  
        long result = CountBaseballPlayers.countLineBufferedReader(file);
        System.out.println(result);
    }
}

Note: Change the path of the file in your case.

Screenshots for additional help:

To find who hit more triples than doubles and home runs, go through this program:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class CSVReader {

    public static void main(String[] args) {

        String csvFile = "/home/rohit/Desktop/baseballplayers.csv";
        BufferedReader br = null;
        String line = "";
        String cvsSplitBy = ",";

        try {

            br = new BufferedReader(new FileReader(csvFile));
            while ((line = br.readLine()) != null) {

                // use comma as separator
                String[] player = line.split(cvsSplitBy);
                String playerName = player[0];
    
                int doubles = Integer.parseInt(player[1]);
                int triples = Integer.parseInt(player[2]);
                int home_runs = Integer.parseInt(player[3]);

                if(triples>doubles && triples>home_runs){

                    System.out.println(player[0]);
                }

            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

Screenshots for additional help:

Note: Above file is updated one

As you can all are having more triples than doubles and home runs, it displays everyone's name.




ALL THE BEST. THANKS.


Related Solutions

Major league baseball team owners have an oligopoly in the market for baseball players
3. Problems and Applications Q3This chapter discusses companies that are oligopolists in the market for the goods they sell. Many of the same ideas apply to companies that are oligopolists in the market for the inputs they buy. If sellers who are oligopolists try to increase the price of goods they sell, the goal of buyers who are oligopolists is to try to decrease the prices of goods they buy Major league baseball team owners have an oligopoly in the market...
The following data represent baseball batting averages for a random sample of National League players near...
The following data represent baseball batting averages for a random sample of National League players near the end of the baseball season. The data are from the baseball statistics section of The Denver Post. 0.194 0.258 0.190 0.291 0.158 0.295 0.261 0.250 0.181 0.125 0.107 0.260 0.309 0.309 0.276 0.287 0.317 0.252 0.215 0.250 0.246 0.260 0.265 0.182 0.113 0.200 (a) Multiply each data value by 1000 to "clear" the decimals. (Keep data values in the same order they appear...
The average age of the players on each of the 30 Major League Baseball teams in...
The average age of the players on each of the 30 Major League Baseball teams in the 2017 season were as follows:               26.6      27.9      27.9      29.9      29.3      28.1              28.4      28.9      27.7      28.7               30.5      29.8      28.5      27.9      30.9      29.3              28.8      28.6      29.1      31.0               30.7      30.3      29.7      31.0      29.4      29.8              29.4      32.7      34.0      31.8 (a) Construct a stem-and-leaf diagram for these data, by using the first two digits of each number as the stem and the third digit as...
25 New York Yankees players from the Major League Baseball, 2016 season, were asked about their...
25 New York Yankees players from the Major League Baseball, 2016 season, were asked about their salaries. They were further classified into pitchers and non-pitchers and the following data on their wages were obtained: 14 pitchers with sample mean = 8,592,211 and sample standard deviation = 8,869,873 11 non-pitchers with sample mean = 8,335,158 and sample standard deviation = 8,969,283 Assume that the population deviations are the same. to. Considering a significance level of 0.01, can it be concluded that...
Think about Major League Baseball! The owners of the major league teams are arguing that they...
Think about Major League Baseball! The owners of the major league teams are arguing that they may have to shut the season down unless the players agree to a significant salary cut. If the players agree, the owners will be able to play games this season. Explain loss-minimization and shut down cases for perfectly competitive firms. Explain why baseball owners may have to resort to a shut-down case and why they may be able to use a loss-minimization case.
Consider the salaries of Major League Baseball players from 1988 to 2011 (you can find that...
Consider the salaries of Major League Baseball players from 1988 to 2011 (you can find that data at http://www.mathcs.org/statistics/datasets/MLBPlayerSalaries.xlsx). Do you think that this data is normally distributed, using common sense? Confirm your suspicion by drawing a frequency histogram of the salary, using 6 bins. Based on that histogram, do you think the median is greater or less than the mean? Note that your answer must include that histogram, properly constructed with 6 bins.
Your friend tells you that the proportion of active Major League Baseball players who have a...
Your friend tells you that the proportion of active Major League Baseball players who have a batting average greater than .300 is less than 0.8, a claim you would like to test. The hypotheses for this test are Null Hypothesis: p ≥ 0.8, Alternative Hypothesis: p < 0.8. If you randomly sample 20 players and determine that 13 of them have a batting average higher than .300, what is the test statistic and p-value? 1) Test Statistic: 1.677, P-Value: 0.953...
a. Major League Baseball now records information about every pitch thrown in every game of every...
a. Major League Baseball now records information about every pitch thrown in every game of every season. Statistician Jim Albert compiled data about every pitch thrown by 20 starting pitchers during the 2009 MLB season. The data set included the type of pitch thrown (curveball, changeup, slider, etc.) as well as the speed of the ball as it left the pitcher’s hand. A histogram of speeds for all 30,740 four-seam fastballs thrown by these pitchers during the 2009 season is...
Refer to the Baseball 2016 data, which report information on the 30 Major League Baseball teams...
Refer to the Baseball 2016 data, which report information on the 30 Major League Baseball teams for the 2016 season. Refer to the variable team salary. Prepare a report on the team salaries. Be sure to answer the following questions in your report. Around what values do the data tend to cluster? Specifically what is the mean team salary? What is the median team salary? Is one measure more representative of the typical team salary than the others? What is...
Refer to the Baseball 2016 data, which report information on the 30 Major League Baseball teams...
Refer to the Baseball 2016 data, which report information on the 30 Major League Baseball teams for the 2016 season. At the .10 significance level, is there a difference in the variation in team salary among the American and National League teams? Create a variable that classifies a team’s total attendance into three groups: less than 2.0 (million), 2.0 up to 3.0, and 3.0 or more. At the .05 significance level, is there a difference in the mean number of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT