Write a C# program to create a States and Capitals guessing game. A method in yo
ID: 3652452 • Letter: W
Question
Write a C# program to create a States and Capitals guessing game. A method in your program should generate a random number between 1 and 50. Your program should use this number to represent one of the 50 U.S states and then display the name of that state. The user will guess the capital of that state. Another method in your program should get the users answer and check to see whether it is correct. Yet another method should print the players score, including both the total number of correct and incorrect guesses. The program should run until the user wants to quit. Use classes, methods, arrays, to develop this programExplanation / Answer
Public Class USCapitals ' Declare module level variables. Private StatesArray() As String = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"} Private CapitalsArray() As String = {"Montgomery", "Juneau", "Phoenix", "Little Rock", "Sacramento", "Denver", "Hartford", "Dover", "Tallahassee", "Atlanta", "Honolulu", "Boise", "Springfield", "Indianapolis", "Des Moines", "Topeka", "Frankfort", "Baton Rouge", "Augusta", "Annapolis", "Boston", "Lansing", "St. Paul", "Jackson", "Jefferson City", "Helena", "Lincoln", "Carson City", "Concord", "Trenton", "Santa Fe", "Albany", "Raleigh", "Bismarck", "Columbus", "Oklahoma City", "Salem", "Harrisburg", "Providence", "Columbia", "Pierre", "Nashville", "Austin", "Salt Lake City", "Montpelier", "Richmond", "Olympia", "Charleston", "Madison", "Cheyenne"} ' Gain access to random class methods & properties Private RandomClass As New Random() Private Correct As Integer Private Sub doCapitalsStateSelection() ' Generate random number between 0 and 49. Dim RandomAInteger As Integer RandomAInteger = RandomClass.Next(50) Dim RandomBInteger As Integer RandomBInteger = RandomClass.Next(50) Dim RandomCInteger As Integer RandomCInteger = RandomClass.Next(50) Dim RandomDInteger As Integer RandomDInteger = RandomClass.Next(50) Select Case Correct Case 0 To 0 End Select ' Get values from the arrays. Dim RandomCapString1 As String = CapitalsArray(RandomAInteger) Dim RandomCapString2 As String = CapitalsArray(RandomBInteger) Dim RandomCapString3 As String = CapitalsArray(RandomCInteger) Dim RandomCapString4 As String = CapitalsArray(RandomDInteger) 'Populate radio buttons. Option1RadioButton.Text = RandomCapString1 Option2RadioButton.Text = RandomCapString2 Option3RadioButton.Text = RandomCapString3 Option4RadioButton.Text = RandomCapString4 Dim RandomSInteger As Integer RandomSInteger = RandomClass.Next(50) Dim RandomStateString As String = StatesArray(RandomSInteger) QuestionLabel.Text = "What is the capital of" + RandomStateString + "?" End Sub Private Sub doStateSelection() Dim RandomSInteger As Integer RandomSInteger = RandomClass.Next(50) Dim RandomStateString As String = StatesArray(RandomSInteger) QuestionLabel.Text = "What is the capital of" + RandomStateString + "?" End Sub Private Sub USCapitals_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Call for new set of State and Capital names. doCapitalsStateSelection() End Sub
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.