Question

Chapter 7, Problem 5PP in Starting out with Visual C# (4th Edition) World Series Champions Teams.txt...

Chapter 7, Problem 5PP in Starting out with Visual C# (4th Edition)

World Series Champions

Teams.txt - This ile contains a list of several Major League baseball teams in alphabetical order. Each team listed in the file has one the World Series at least once.

WorldSeriesWinners.txt - This file contains a chronological list of the World Series' winning teams from 1903 through 2012.

Create an application that displays the contents of the Teams.txt file in a ListBox control. When the user selects a team in the ListBox, the application should display the number of times that team has won the world series in the time period form 1903 through 2012.

Tip: Read the contents of the WorldSeriesWinners.txt file into a List or an array. When the user selects a team, an algorithm should step through the list or array counting the number of times the selected team appears.

Use a (drop down list) combo box for teams, rather than a list box.

Read the files at Form Load time only.
This requires a private (class level) List or array variable. Keep all other variables local.

In addition, your solution must accommodate not only the provided file (WorldSeriesWinners.txt), but one of any size.

Display the number of wins in the combo box’s SelectedIndexChanged event

Create (Integer) method CalculateWins with a string parameter selectedTeam

Pass the selected item of the combo box as an argument to selectedTeam

0 1
Add a comment Improve this question Transcribed image text
Answer #1

// A c# program display the number of times that team has won the world series in the time period form 1903 through 2012.

using System;
using System.Windows.Forms;

namespace WorldSeriesChampions
{
   public partial class Form1 : Form
   {
       public Form1
       {
           InitializeComponent();
       }
      
       // code for the form which has a dropdown combobox list abd label.
       private void Form1_Load(object sender, EventArgs e)
   {      
           comboBox1.Sorted = true;
           comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
      
           // read contents of Team.txt file into a string array.
           string[] lineOfContents = File.ReadAllLines("Teams.txt");
      
           //add each team name into dropdown combobox.
           foreach (var line in lineOfContents)
           {
               comboBox1.Items.Add(line);           
           }
      }

      // code that runs when a team is selected in combobox list by user, and displays no. of times the team won world series.
      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
           if(selectedTeam(comboBox1.Text) == 0)
               label1.Text = comboBox1.Text + "never WON the world series";
           else
               label1.Text = comboBox1.Text + "WON" + selectedTeam(comboBox1.Text) + "times";
label1.BorderStyle = BorderStyle.FixedSingle;
label1.TextAlign = ContentAlignment.MiddleCenter;
       }

       // function to find no. of times a team won world series.
       private int selectedTeam(string team)
       {
           // read contents of WorldSeriesWinners.txt file into a string array
           string[] listOfWinners = File.ReadAllLines("WorldSeriesWinners.txt");
           int score = 0;
           foreach (var line in listOfWinners)
           {
               if(line.Equals(team))
                   score++;          
           }
           return score;
       }
   }  
}

Add a comment
Know the answer?
Add Answer to:
Chapter 7, Problem 5PP in Starting out with Visual C# (4th Edition) World Series Champions Teams.txt...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python You will download a file by right clicking on the file name then chose Save...

    Python You will download a file by right clicking on the file name then chose Save link As: WorldSeriesWinners.txt . This file contains a chronological list of the World Series winning teams from 1903 through 2009. (The first line in the file is the name of the team that won in 1903, and the last line is the name of the team that won in 2009. Note that the World Series was not played in 1904 or 1994.) Write a...

  • Can you give me this program working in C++ please 95% oo H20 LTE 9:01 PM...

    Can you give me this program working in C++ please 95% oo H20 LTE 9:01 PM ehacc hacc.edu HACC-Harrisburg Area Community Fahringer College CPS 161 Computer Science Program #7 20 points Program Due: Monday, March 21st Word Series Task: Write a program that displays the contents of the Teams txt file on the screen and prompts the user to enter the name of one of the teams. The program should then display the number of times that team has won...

  • Please answer Question 4 WITH A C# PROGRAM!!!!!! THANK YOU! File Edit View History Bookmarks Tools...

    Please answer Question 4 WITH A C# PROGRAM!!!!!! THANK YOU! File Edit View History Bookmarks Tools Help Share GEP IIIA Moorhead, MN 10-Day Weathe X N NDSU Faculty and Staff | North x D C#.NET - CSCI 213: Modern Sol X VitalSource Bookshelf: Starting x + + → OO - https://bookshelf.vitalsource.com/#/books/9780134400433/cf1/6 90% *** * Cambie Meble alle... S N 10 Crosby Derek Lam ... Alterna Caviar Anti-Ag... U C# Tutorial For Beginn... BE Celsius Fahrenheit con... Charter Club Sweater. Folklorama...

  • Starting out with Python 4th edition I need help I followed a tutorial and have messed...

    Starting out with Python 4th edition I need help I followed a tutorial and have messed up also how does one include IOError and IndexError exception handling? I'm getting errors: Traceback (most recent call last): File, line 42, in <module> main() File , line 37, in main winning_times = years_won(user_winning_team_name, winning_teams_list) File , line 17, in years_won for winning_team_Index in range(len(list_of_teams)): TypeError: object of type '_io.TextIOWrapper' has no len() Write program champions.py to solve problem 7.10. Include IOError and IndexError...

  • C# Visual Studio Problem You are given a file named USPopulation.txt. The file contains the midyear...

    C# Visual Studio Problem You are given a file named USPopulation.txt. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth. Create an application that reads the file’s contents into an array or a List. The application should display the following data (statistics) in read-only textboxes. The average population during...

  • I need help regarding my Visual Basic code ISC/ITE 285 Homework Due: Monday, January 28 by...

    I need help regarding my Visual Basic code ISC/ITE 285 Homework Due: Monday, January 28 by 11:55 pm Create a text file named "Grades.txt" which will contain a list of numeric grades. Save the file in the projects Bin/Debug folder. A sample of the file contents is shown below: 80 96 95 86 54 97 Create a string array that will be populated from the file "Grades.txt" when the array is created (Class-level array). Also create a numeric array that...

  • PYTHON Text file Seriesworld attached below and it is a list of teams that won from...

    PYTHON Text file Seriesworld attached below and it is a list of teams that won from 1903-2018. First time mentioned won in 1903 and last team mentioned won in 2018. World series wasn’t played in 1904 and 1994 and the file has entries that shows it. Write a python program which will read this file and create 2 dictionaries. The first key of the dictionary should show name of the teams and each keys value that is associated is the...

  • Please Read it all and carefully In visual basic(vba)do the following program Summary INGE Industry, Inc....

    Please Read it all and carefully In visual basic(vba)do the following program Summary INGE Industry, Inc. needs a program in which the date and temperature in Celsius degrees of an industry laboratory are recorded and stored in a sequential file. In addition, you can see the recorded data and convert the temperatures in the following units: Fahrenheit, Kelvin and Rankine. In addition, they want to see a linear graph that reflects how the temperature has fluctuated day by day, for...

  • What are the first few steps to solving this on Microsoft Visual Basis

    What are the first few steps to solving this on Microsoft Visual Basis Imagine your boss hands you a large bag. You are told it contains an unknown number of American currency notes (i.e. paper money). Your job is to sort the entire bag and provide a count for each of the following de $10, $20, $50, and $100. s: $1, $2, $5 You most likely would create a pile for each denomination. As you extract a bill from the...

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT