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
  • 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...

  • 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...

  • 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...

  • 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...

  • Must be done in C# please! Thanks! In this assignment you will create a program named...

    Must be done in C# please! Thanks! In this assignment you will create a program named Test Scores that displays the average of all tests; average midterm score; average final score; and displays the midterm or final score of a particular student. Create a class level two dimensional integer array named Grades initialized with the following data: 897 242 301 987 116 450 865 128 992 109 88 75 94 70 90 87 81 79 97 79 78 80 92...

  • ****PLEASE CODE IN C++ and line doc explaining what is happening!***** **HERE IS THE INPUT FILE(.txt)*****...

    ****PLEASE CODE IN C++ and line doc explaining what is happening!***** **HERE IS THE INPUT FILE(.txt)***** Ottawa Senators New York Rangers Boston Bruins Montreal Canadiens Montreal Canadiens Toronto Maple Leafs New York Rangers Chicago Blackhawks Montreal Maroons Detroit Red Wings Detroit Red Wings Chicago Blackhawks Boston Bruins New York Rangers Boston Bruins Toronto Maple Leafs Detroit Red Wings Montreal Canadiens Toronto Maple Leafs Montreal Canadiens Toronto Maple Leafs Toronto Maple Leafs Toronto Maple Leafs Detroit Red Wings Toronto Maple Leafs...

  • 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...

  • 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...

  • 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...

  • This homework problem has me pulling my hair out. We are working with text files in Java using Ne...

    This homework problem has me pulling my hair out. We are working with text files in Java using NetBeans GUI application. We're suppose to make a movie list and be able to pull up movies already in the text file (which I can do) and also be able to add and delete movies to and from the file (which is what I'm having trouble with). I've attached the specifications and the movie list if you need it. Any help would...

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
ADVERTISEMENT