29 November 2011, 7:51 pm
Here's the instructions the teacher gave me: Your application will display a multiple choice question about the capital of one of the states (e.g. “What is the capital of Oregon?”) and provide four possible answers using radio buttons. oPseudocode Generate a random number between 0 and 49 Update the question label on the form with a question about a randomly selected state (e.g. If the random number was 0, the question would e “What is the capital of Alabama?”) Save the correct answer (the capital name) in the class variable. (See class data section above). Update each of the four answers with randomly selected capital names (note that this can result in duplicates, but that doesn’t affect the operation of the program). Replace one fo the four answers with the correct answer (randomly generate a number between 0 and 3 and use a case statement to put the answer in one of the four possible answers). So basically I have no idea how to make one of the correct choices come up. Heres my code so far: 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) ' 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)... Read More »