Need help writing the Visual Basic code for this problem. World Series Champions
ID: 3779621 • Letter: N
Question
Need help writing the Visual Basic code for this problem.
World Series Champions
In the Chap9 folder of the student sample programs, you will find the following files:
-Teams.txt---This file contains a list of several Major League baseball teams in alphabetical order. Each team listed in the file has won the World Series at least once.
-WorldSeriesWinners.txt---This file contains a chronological list of the World Series' winning teams from 1903 through 2012. (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 2012. Note that the World Series was not played in 1904 or 1994.)
Create and 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 from 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.
Teams.txt:
Anaheim Angels, Arizona Diamonbacks, Atlanta Braves, Baltimore Orioles, Boston Americans, Boston Braves, Boston Red Socks, Brooklyn Dodgers, Chicago Cubs, Chicago White Sox, Cincinnati Reds, Cleveland Indians, Detroit Tigers, Florida Marlins, Kansas City Royals, Los Angeles Dodgers, Milwaukee Braves, Minnesota Twins, New York Giants, New York Mets, New York Yankees, Oakland Athletics, Philadelphia Athletics, Philadelphia Phillies, Pittsburgh Pirates, San Francisco Giants, St. Louis Cardinals, Toronto Blue Jays, Washington Senators
WorldSeriesWinners.txt:
Boston Americans, New York Giants, Chicago White Sox, Chicago Cubs, Chicago Cubs, Pittsburgh Pirates, Philadelphia Athletics, Philadelphia Athletics, Boston Red Sox, Philadelphia Athletics, Boston Braves, Boston Red Sox, Boston Red Sox, Chicago Red Sox, Boston Red Sox, Cincinnati Reds, Cleveland Indians, New York Giants, NEw York Giants, New York Yankees, Washington Senators, Pittsburgh Pirates, St. Louis Cardinals, New York Yankees, New York Yankees, Philadelphia Athletics, Philadelphia Athletics, St. Louis Cardinals, New York Yankees, New York Giants, St. Louis Cardinals, Detroit Tigers, New York Yankees, New York Yankees, New York Yankees, New York Yankees, Cincinnati Reds, New York Yankees, St. Louis Cardinals, New York Yankees, St. Louis Cardinals, Detroit Tigers, St. Louis Cardinals, New York Yankees, Cleveland Indians, New York Yankees, New York Yankees, New York Yankees, New York Yankees, New York Yankees, New York Giants, Brooklyn Dodgers, New York Yankees, Milwaukee Braves, New York Yankees, Los Angeles Dodgers, Pittsburgh Pirates, New York Yankees, New York Yankees, Los Angeles Dodgers, St. Louis Cardinals, Los Angeles Dodgers, Baltimore Orioles, St. Louis Cardinals, Detroit Tigers, New York Mets, Baltimore Orioles, Pittsburgh Pirates, Oakland Athletics, Oakland Athletics, Oakland Athletics, Cincinnati Reds, Cincinnati Reds, New York Yankees, New York Yankees, Pittsburgh Pirates, Philadelphia Phillies, Los Angeles Dodgers, St. Louis Cardinals, Baltimore Orioles, Detroit Tigers, Kansas City Royals, New York Mets, Minnesota Twins, Los Angeles Dodgers, Oakland Athletics, Cincinnati Reds, Minnesota Twins, Toronto Blue Jays, Toronto Blue Jays, Atlanta Braves, New York Yankees, Florida Marlins, New York Yankees, New York Yankees, New York Yankees, Arizona Diamondbacks, Anaheim Angels, Florida Marlins, Boston Red Sox, Chicago White Sox, St. Louis Cardinals, Boston Red Sox, Philadelphia Phillies, New York Yankees, San Francisco Giants, St. Louis Cardinals, San Francisco Giants
Explanation / Answer
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="LB1" runat="server" AutoPostBack="true"></asp:ListBox>
<div>
No of times the team has won the World series :
<asp:Label ID ="lbl1" runat ="server"></asp:Label>
</div>
</div>
</form>
</body>
</html>
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string line = string.Empty;
System.IO.StreamReader file = new System.IO.StreamReader("C:\Users acherlas\Desktop\Chap9\Teams.txt");
while ((line = file.ReadLine()) != null)
{
LB1.Items.Add(line.Trim());
}
file.Close();
lbl1.Text = "0";
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int count = 0;
string line = string.Empty;
System.IO.StreamReader file1 = new System.IO.StreamReader("C:\Users acherlas\Desktop\Chap9\WorldSeriesWinners.txt");
while ((line = file1.ReadLine()) != null)
{
if (LB1.SelectedValue.Contains(line.Trim()))
{
count++;
}
}
file1.Close();
lbl1.Text = Convert.ToString(count);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.