Here is a simple Visual Basic (VB) program for a shopping mall:
Program Description:
This program allows users to:
1. View available products
2. Add products to cart
3. Remove products from cart
4. Calculate total cost
5. Make payment
Code:
```
Imports System.Collections.Generic
Public Class ShoppingMall
Private products As New List(Of Product)
Private cart As New List(Of Product)
Public Sub New()
' Initialize products
products.Add(New Product("Shirt", 20.99))
products.Add(New Product("Pants", 30.99))
products.Add(New Product("Shoes", 50.99))
End Sub
Public Sub ViewProducts()
Console.WriteLine("Available Products:")
For Each product In products
Console.WriteLine($"{product.Name} - ${product.Price}")
Next
End Sub
Public Sub AddToCart(productName As String)
For Each product In products
If product.Name = productName Then
cart.Add(product)
Console.WriteLine($"Added {productName} to cart.")
Return
End If
Next
Console.WriteLine("Product not found.")
End Sub
Public Sub RemoveFromCart(productName As String)
For Each product In cart
If product.Name = productName Then
cart.Remove(product)
Console.WriteLine($"Removed {productName} from cart.")
Return
End If
Next
Console.WriteLine("Product not found in cart.")
End Sub
Public Sub CalculateTotal()
Dim total As Decimal = 0
For Each product In cart
total += product.Price
Next
Console.WriteLine($"Total: ${total}")
End Sub
Public Sub MakePayment()
Console.WriteLine("Payment successful.")
cart.Clear()
End Sub
End Class
Public Class Product
Public Property Name As String
Public Property Price As Decimal
Public Sub New(name As String, price As Decimal)
Me.Name = name
Me.Price = price
End Sub
End Class
Module Program
Sub Main()
Dim mall As New ShoppingMall()
While True
Console.WriteLine("Shopping Mall Menu:")
Console.WriteLine("1. View Products")
Console.WriteLine("2. Add to Cart")
Console.WriteLine("3. Remove from Cart")
Console.WriteLine("4. Calculate Total")
Console.WriteLine("5. Make Payment")
Console.WriteLine("6. Exit")
Dim choice As String = Console.ReadLine()
Select Case choice
Case "1"
mall.ViewProducts()
Case "2"
Console.Write("Enter product name: ")
Dim productName As String = Console.ReadLine()
mall.AddToCart(productName)
Case "3"
Console.Write("Enter product name: ")
Dim productName As String = Console.ReadLine()
mall.RemoveFromCart(productName)
Case "4"
mall.CalculateTotal()
Case "5"
mall.MakePayment()
Case "6"
Exit While
Case Else
Console.WriteLine("Invalid choice. Please try again.")
End Select
End While
End Sub
End Module
```
How to Run:
1. Create a new VB.NET console application project in Visual Studio.
2. Copy and paste the above code into the project.
3. Run the project using F5 or the "Start" button.
Example Use Cases:
1. View available products: Choose option 1 from the menu.
2. Add product to cart: Choose option 2, enter the product name (e.g., "Shirt").
3. Remove product from cart: Choose option 3, enter the product name (e.g., "Shirt").
4. Calculate total cost: Choose option 4.
5. Make payment: Choose option 5.
No comments:
Post a Comment