Create a VB.NET application that allows users to rate the book ‘ASP.NET with C#’ by Wrox publication. Provide three choices: i) Good ii) Satisfactory iii) Bad. After the user votes, present the result in percentage using labels next to the choices.

Answer:

Public Class Form1
    Dim goodVotes As Integer = 0
    Dim satisfactoryVotes As Integer = 0
    Dim badVotes As Integer = 0
    Dim totalVotes As Integer = 0

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If RadioButton1.Checked Then
            goodVotes += 1
        ElseIf RadioButton2.Checked Then
            satisfactoryVotes += 1
        ElseIf RadioButton3.Checked Then
            badVotes += 1
        End If

        totalVotes += 1

        Dim goodPercentage As Double = 0
        Dim satisfactoryPercentage As Double = 0
        Dim badPercentage As Double = 0

        If totalVotes > 0 Then
            goodPercentage = (goodVotes / totalVotes) * 100
            satisfactoryPercentage = (satisfactoryVotes / totalVotes) * 100
            badPercentage = (badVotes / totalVotes) * 100
        End If

        Label1.Text = "Good: " & goodPercentage.ToString("F2") & "%"
        Label2.Text = "Satisfactory: " & satisfactoryPercentage.ToString("F2") & "%"
        Label3.Text = "Bad: " & badPercentage.ToString("F2") & "%"

        RadioButton1.Checked = False
        RadioButton2.Checked = False
        RadioButton3.Checked = False
    End Sub
End Class
Scroll to Top