0% found this document useful (0 votes)
1 views7 pages

Ass 2 App Programming

The document outlines a program for registering six units, featuring a user interface that includes a label, combo box for unit selection, and a registration button. It details the successful registration of each unit (A to F) and includes code snippets demonstrating the program's functionality, including unit prerequisites and registration status. The program ensures that prerequisites are met before registration and tracks the total amount to be paid.

Uploaded by

alvinropk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views7 pages

Ass 2 App Programming

The document outlines a program for registering six units, featuring a user interface that includes a label, combo box for unit selection, and a registration button. It details the successful registration of each unit (A to F) and includes code snippets demonstrating the program's functionality, including unit prerequisites and registration status. The program ensures that prerequisites are met before registration and tracks the total amount to be paid.

Uploaded by

alvinropk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ASSIGNMENT 2

Here is a program that is used to register 6 units

This is the interface showing the design view, I used a Label to enter the program heading and the used
the combo box for units selection, then the button to register the units.

Here is the design interface:

When we run the program here is how we registered for the six units.

The first Unit was Unit A and it was successfully registered


The second Unit was Unit B and it was successfully registered;

The third Unit was Unit C and it was registered successfully;

The fourth unit was Unit D and it was registered successfully;


The fifth unit was Unit E and it was registered successfully;

The last unit was unit F and it was successfully registered;


After all Units were registered, when the register button was clicked, it indicated that all the units were
registered;

Here are the codes screenshots for the above program;


Here are the lines of codes extracted for the above program;
Public Class Form1
' Dictionary to store units and their prerequisites
Dim unitsWithPrerequisites As New Dictionary(Of String, String)

' Dictionary to store units and their registration status


Dim unitsRegistrationStatus As New Dictionary(Of String, Boolean)

' Variable to store the total amount to be paid


Dim totalAmount As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
' Initialize units with prerequisites
unitsWithPrerequisites.Add("Unit A", "")
unitsWithPrerequisites.Add("Unit B", "Unit A")
unitsWithPrerequisites.Add("Unit C", "Unit A")
unitsWithPrerequisites.Add("Unit D", "Unit B")
unitsWithPrerequisites.Add("Unit E", "Unit C")
unitsWithPrerequisites.Add("Unit F", "Unit D")

' Initialize units registration status


For Each unit As String In unitsWithPrerequisites.Keys
unitsRegistrationStatus.Add(unit, False)
Next

' Populate combo box with units


For Each unit As String In unitsWithPrerequisites.Keys
ComboBox1.Items.Add(unit)
Next
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles Button1.Click
' Check if the student has already registered for 6 units
Dim unitsRegistered As Integer = 0
For Each status As Boolean In unitsRegistrationStatus.Values
If status Then
unitsRegistered += 1
End If
Next

If unitsRegistered >= 6 Then


MsgBox("You have already registered for 6 units.")
Exit Sub
End If

' Check if the selected unit is already registered or if prerequisites are not
met
Dim selectedUnit As String = ComboBox1.SelectedItem.ToString()
If unitsRegistrationStatus(selectedUnit) Then
MsgBox("You have already registered for this unit.")
Exit Sub
End If

Dim prerequisite As String = unitsWithPrerequisites(selectedUnit)


If prerequisite <> "" AndAlso Not unitsRegistrationStatus(prerequisite) Then
MsgBox("You must complete the prerequisite " & prerequisite & " before
registering for this unit.")
Exit Sub
End If

' Register the selected unit


unitsRegistrationStatus(selectedUnit) = True
totalAmount += 10000

' Display registration status


MsgBox("Successfully registered for " & selectedUnit & ". Total amount to be
paid: " & totalAmount)

' Disable unit from combo box if already registered


ComboBox1.Items.Remove(selectedUnit)
End Sub
End Class

You might also like