Question

In: Computer Science

Using Java create an application that will read a tab-delimited file that displays the MLB standings...

Using Java create an application that will read a tab-delimited file that displays the MLB standings Below:

League AL East

Tampa Bay 37 20

NY Yankees 32 24

Toronto 29 27

Baltimore 23 33

Boston 22 34

League AL Central

Minnesota 35 22

Chi White Sox 34 23

Cleveland 33 24

Kansas City 23 33

Detroit 22 32

League AL West

Oakland 34 21

Houston 28 28

LA Angels 26 31

Seattle 25 31

Texas 19 37

League NL East

Atlanta 34 22

Miami 28 28

Philadelphia 28 29

NY Mets 26 31

Washington 23 34

League NL Central

Chi Cubs 32 25

St. Louis 27 26

Cincinnati 29 28

Milwaukee 27 28

Pittsburgh 18 39

League NL West

LA Dodgers 39 17

San Diego 34 22

San Francisco 28 28

Colorado 25 31

Arizona 22 34

and display expanded standings in a nicely formatted way, like so:

*****************************************

* BASEBALL ANALYZER *

*****************************************



Enter the name of the standings file:


Which standings would you like to see?

1. AL East

2. AL Central

3. AL West

4. NL East

5. NL Central

6. NL West

7. Overall

8. Exit

Enter the number of your choice: 1

Team Wins Losses Pct. Behind

-----------------------------------------------

Tampa Bay 37 20 0.649        

NY Yankees 32 24 0.571 4.5

Toronto 29 27 0.518 7.5

Baltimore 23 33 0.411 13.5

Boston 22 34 0.393 14.5

Which standings would you like to see?

1. AL East

2. AL Central

3. AL West

4. NL East

5. NL Central

6. NL West

7. Overall

8. Exit

Enter the number of your choice: 2

Team Wins Losses Pct. Behind

-----------------------------------------------

Minnesota 35 22 0.614        

Chi White Sox 34 23 0.596 1.0

Cleveland 33 24 0.579 2.0

Kansas City 23 33 0.411 11.5

Detroit 22 32 0.407 11.5

Solutions

Expert Solution

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU

Code

import java.awt.*;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.concurrent.*;

//Start code
class BaseballStandings {

  /**
   *This fucntion prints out the welcome banner
   */
  public static void Welcome() {
    System.out.println("******************************************");
    System.out.println(" BASEBALL STANDING ANALYZER");
    System.out.println("******************************************");
  } //END welcome

  /**
   *This fucntion Will take in The scanner tool
   * Print out a list of choices to the user and then will ask the user for their choice
   *This choice will then be returned to the main
   *@return choice
   */
  public static int MenuChoice(Scanner sc) {
    System.out.println("Which Standings would you like to see?"); //ask user
    System.out.println("1. AL East\n2. Al Central\n3. AL West"); //AL
    System.out.println("4. NL East\n5. NL Central\n6. NL West"); //nl
    System.out.println("7. Overall\n8. Exit"); //other
    System.out.print("Enter your choice: "); //enter choice
    int choice = sc.nextInt();
    return choice;
  } // end MenuChoice

  /**
   *This function will take in a string caleld line and then compute the average
   *It will do this by adding the wins and losses and then dividing wins by the total gamesPlayed
   *@return avg
   */
  public static double getAvg(String line) {
    String[] parts = line.split("\t");
    double gamesPlayed =
      (Integer.parseInt(parts[1])) + (Integer.parseInt(parts[2]));
    double avg = (Integer.parseInt(parts[1])) / gamesPlayed;
    return avg;
  } //end getAvg

  /**
   *This fucntion will take choice 1-6 and order the teams by their win vs loss Percentage
   *This fucntion calls the fucntion getAvg to compute the averages and then order them.
   *This Fucntion will also print the results out in a easy to read list.
   */
  public static void displayStats(ArrayList<String> standings) {
    String[] parts;
    double avg, gamesB; //variables for fucntion calls
    System.out.println(
      "----------------------------------------------------------------"
    );
    System.out.println("Teams: Wins: Loses: Pct: Games Behind:");
    System.out.println(
      "----------------------------------------------------------------"
    );
    for (String standing : standings) {
      parts = standing.split("\t");
      avg = getAvg(standing);
      //gamesB = gamesBehind(standings);
      System.out.printf(
        "%-15s%-8s%-8s%6.2f \n ",
        parts[0],
        parts[1],
        parts[2],
        avg
      );
      //System.out.println(parts[1]);
      //System.out.println(parts[2]);

    } //end for
    //       System.out.println(standings);
  } //end displayStats

  /**
   *displayStats2
   *fucntion for ordering stats by winning percentage for option 7
   *It will take in the Teams and then order the teams by the PCT
   *It will print ou the team name which is aprts[0] and the average calculated by
   *getAvg
   */
  public static void displayStats2(ArrayList<String> standings) {
    String[] parts;
    double avg;
    System.out.println("-----------------------------");
    System.out.println("Teams: Pct:");
    System.out.println("-----------------------------");
    for (String standing : standings) {
      parts = standing.split("\t");
      avg = getAvg(standing);
      System.out.printf("%-15s%6.2f\n ", parts[0], avg);
      //System.out.println(parts[1]);
      //System.out.println(parts[2]);

    } //end for
    //       System.out.println(standings);
  } //end displayStats2

  /**
   *This Fucntion will sort the list by the average
   *It will use the fucntion getAvg to compare two averages and then order them
   */
  public static void byAvg(ArrayList<String> teams, String line) {
    double avg1 = getAvg(line); //fucntion call
    double avg2;
    int pos = -1;
    for (int i = 0; i < teams.size(); i++) {
      avg2 = getAvg(teams.get(i)); //fucntion call to getAvg to get average of two scores
      if (avg1 > avg2) {
        pos = i;
        break;
      } //end if
    }
    if (pos < 0) {
      teams.add(line);
    } else {
      teams.add(pos, line);
    } //end for Secondary if Loop
  }

  //gamesBehind function
  /**
   public static double gamesBehind(ArrayList<String> standings) {
       String [] parts;
       String leaderTeam;
       double holder1, holder2, holder3;
       double newLeader;
       double stats; //will be return variable
       for(int i = 0; i < standings.size(); i++){
           parts = standing.split("\t");
           holder1 = Integer.parseInt(parts[1]);
           holder2 = Integer.parseInt(parts[2]);
           holder3 = holder1 - holder2
       }
       //stats = 1; //test return
       return lead1;
   }//end gamesBehind
   */
  //main
  public static void main(String[] args) {
    /**
     *This is the main part of the program and will open a file or reject it
     *take in the user choice and call fucntins for this
     * It will also take the users choice and designate the correct parts of the file
     *Fucntions used are: Welcome, menuChoice, byAvg, displayStats and displayStats2
     */
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the name of the file: ");
    String fname = sc.nextLine(); //file name
    //create array lists
    ArrayList<String> aleast = new ArrayList<String>();
    ArrayList<String> alcentral = new ArrayList<String>();
    ArrayList<String> alwest = new ArrayList<String>();
    ArrayList<String> nleast = new ArrayList<String>();
    ArrayList<String> nlcentral = new ArrayList<String>();
    ArrayList<String> nlwest = new ArrayList<String>();
    ArrayList<String> target = null;
    ArrayList<String> overall = new ArrayList<String>(); //every team
    //MenuChoice(sc);
    String line, sem;
    String[] parts;
    boolean goAhead;
    int choice;
    try {
      Scanner fsc = new Scanner(new File(fname));
      while (fsc.hasNextLine()) {
        line = fsc.nextLine();
        parts = line.split("\t");
        if (parts[0].equalsIgnoreCase("LEAGUE")) {
          sem = parts[1].toUpperCase();
          if (sem.equalsIgnoreCase("AL EAST")) {
            target = aleast;
          } else if (sem.equalsIgnoreCase("AL CENTRAL")) {
            target = alcentral;
          } else if (sem.equalsIgnoreCase("AL West")) {
            target = alwest;
          } else if (sem.equalsIgnoreCase("NL EAST")) {
            target = nleast;
          } else if (sem.equalsIgnoreCase("NL CENTRAL")) {
            target = nlcentral;
          } else if (sem.equalsIgnoreCase("NL WEST")) {
            target = nlwest;
          }
        } else {
          target.add(line);
          byAvg(overall, line); //function call//
        } //end if
      } //end while
      Welcome(); //welcome banner
      fsc.close(); //close scanner
      goAhead = true;
    } catch (Exception ex) {
      System.out.println("Couldn't read the file!");
      goAhead = false;
    } //end catch
    if (goAhead) {
      do {
        choice = MenuChoice(sc);
        if (choice == 1) {
          displayStats(aleast);
        } else if (choice == 2) {
          displayStats(alcentral);
        } else if (choice == 3) {
          displayStats(alwest);
        } else if (choice == 4) {
          displayStats(nleast);
        } else if (choice == 5) {
          displayStats(nlcentral);
        } else if (choice == 6) {
          displayStats(nlcentral);
        } else if (choice == 7) {
          displayStats2(overall);
        } //end else and if loop
      } while (choice != 8);
    } //end if
  } //end main
} //end program

League AL East
Tampa Bay 37 20
NY Yankees 32 24
Toronto 29 27
Baltimore 23 33
Boston 22 34
League AL Central
Minnesota 35 22
Chi White Sox 34 23
Cleveland 33 24
Kansas City 23 33
Detroit 22 32
League AL West
Oakland 34 21
Houston 28 28
LA Angels 26 31
Seattle 25 31
Texas 19 37
League NL East
Atlanta 34 22
Miami 28 28
Philadelphia 28 29
NY Mets 26 31
Washington 23 34
League NL Central
Chi Cubs 32 25
St. Louis 27 26
Cincinnati 29 28
Milwaukee 27 28
Pittsburgh 18 39
League NL West
LA Dodgers 39 17
San Diego 34 22
San Francisco 28 28
Colorado 25 31
Arizona 22 34


Related Solutions

Create a PowersTable application that displays a table of of powers. ( Java Programing )
Create a PowersTable application that displays a table of of powers. ( Java Programing )
How to create a JS application using the code below that displays the lists of grades...
How to create a JS application using the code below that displays the lists of grades in their corresponding letter grade textbox and each grade being sorted from lowest to highest. <!DOCTYPE> <html> <head> <title>EXAM01_03</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#ans4,#ans5,#numbers{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> </head> <body>    <form>    <div class="title"><label>EXAM01_03</label></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>Enter Grade List:</label></div><div style="float:left;"><input type="text" id="numbers" /></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>A:</label></div><div...
Using the Ch04problems.xls file and the states tab, create a scatter chart examining the relationship between...
Using the Ch04problems.xls file and the states tab, create a scatter chart examining the relationship between total discharges and total patient days. Describe the relationship between these two variables.
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java...
In Java Develop, test, and execute a graphics application for simulations using Java. Create a Java application. Given a set of events, choose the resulting programming actions. Understand the principles behind Java. Understand the basic principles of object-oriented programming including classes and inheritance. Deliverables .java files as requested below. Requirements Create all the panels. Create the navigation between them. Start navigation via the intro screen. The user makes a confirmation to enter the main panel. The user goes to the...
Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and...
Write a Java application "WellFormedExpression.java". Start with the file attached here. Please read the comments and complete the function 'isWellFormed()'. It also has the main() to test the function with several input strings. Feel free to change and add more tests with different kinds of input data for correct implementation. Note that you need MyStack.java and Stackinterface.java in the same package. WellFormedExpression.java package apps; public class WellFormedExpression {    static boolean isWellFormed(String s) {        /**** Create a stack...
Read previously created binary file using ObjectInputStream Create an appropriate instance of HashMap from Java library...
Read previously created binary file using ObjectInputStream Create an appropriate instance of HashMap from Java library Populate the HashMap with data from binary file Display the information read in a user friendly format Problem: Given: Words.dat – a binary file consisting of all the words in War and Peace Goal: Read the words in from the binary file and figure out how many times each word appears in the file. Display the results to the user. Use a HashMap with...
Assignment: Create data file consisting of integer, double or String values. Create unique Java application to...
Assignment: Create data file consisting of integer, double or String values. Create unique Java application to read all data from the file echoing the data to standard output. After all data has been read, display how many data were read. For example, if 10 integers were read, the application should display all 10 integers and at the end of the output, print "10 data values were read" My issue is displaying how many integers were read and how many strings...
Write a java program that can create, read, and append a file. Assume that all data...
Write a java program that can create, read, and append a file. Assume that all data written to the file are string type. One driver class and a class that contains the methods. The program should have three methods as follows: CreateFile - only creating a file. Once it create a file successfully, it notifies to the user that it creates a file successfully. ReadingFile - It reads a contents of the file. This method only allow to read a...
Using java, I need to make a program that reverses a file. The program will read...
Using java, I need to make a program that reverses a file. The program will read the text file character by character, push the characters into a stack, then pop the characters into a new text file (with each character in revers order) EX: Hello World                       eyB       Bye            becomes    dlroW olleH I have the Stack and the Linked List part of this taken care of, I'm just having trouble connecting the stack and the text file together and...
Using JAVA The following code is able to read integers from a file that is called...
Using JAVA The following code is able to read integers from a file that is called "start.ppm" onto a 3d array called "startImage". Implement the code by being able to read from another file (make up any file name) and save the data onto another 3d array lets say you call that array "finalImage". The purpose of this will be to add both arrays and then get the average Save the average onto a separte 3darray,lets say you call it...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT