In: Computer Science
Make a Console application
Language should be Visual Basic
You will be simulating an ATM machine as much as possible
Pretend you have an initial deposit of 1000.00. You will
Prompt the user with a Main menu:
Enter 1 to deposit
Enter 2 to Withdraw
Enter 3 to Print Balance
Enter 4 to quit
When the user enters 1 in the main menu, your program will prompt the user to enter the deposit amount.
If the user enter more than 2000, Print "Deposit of more than $2000 is not allowed" and
Prompt the user with a SubMenu:
Enter 1 for the Main Menu. If user enters 1, display the main menu
Enter 0 to quit. If user enter 0, exit the application
if the user enters less than 2000,
Print "Deposit Transaction Successful" and
Add the amount to the Balance
Prompt the user with a SubMenu:
Enter 1 for the Main Menu. If user enters 1, display the main menu
Enter 0 to quit. If user enter 0, exit the application
When the user enters 2 in the main menu, your program will prompt the user to enter a withdraw amount.
If the user enter more than 200, Print "Withdrawing more than $200 is not allowed
Prompt the user with a SubMenu:
Enter 1 for the Main Menu. If user enters 1, display the main menu
Enter 0 to quit. If user enter 0, exit the application
If the user enter less than 200, Print "Withdraw Transaction Successful."
deduct the amount from the Balance
Prompt the user with a SubMenu:
Enter 1 for the Main Menu. If user enters 1, display the main menu
Enter 0 to quit. If user enter 0, exit the application
When the user enters 3 in the main menu, print the balance as "Your Current Balance = "
Prompt the user with a SubMenu:
Enter 1 for the Main Menu. If user enters 1, display the main menu
Enter 0 to quit. If user enter 0, exit the application
When the user enters 4 in the main menu, exit the application
When the user enters other than 1-4, print "Invalid Transaction Requested"
Here is the output of my program, with user entered numbers highlighted in yellow
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
1
Enter the amount to Deposit
3000
Deposit More than $2000 is not allowed
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
1
Enter the amount to Deposit
1999
Deposit Transaction successful
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
3
Your Current Balance =2999
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
2
Enter the amount to Withdraw
250
Withdrawing More than $200 is not allowed
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
2
Enter the amount to Withdraw
150
Withdraw Transaction successful
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
3
Your Current Balance =2849
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
5
Invalid Transaction requested
Enter 1 to Main Menu
Enter 2 to Quit
1
Enter 1 for Deposit
Enter 2 for Withdraw
Enter 3 for Print Balance
Enter 4 for Quit
4
You should test for the same output as mine. Upload the VB script and screenshot of your application.
Short Summary:
**************Please upvote the answer and appreciate our time.************
**************************************************************************************************************
Source Code:
ATM.vb File:
Public Class ATM
' Private attribute
Private balance As Double
Private Const MAX_DEPOSIT As Integer = 2000
Private Const MAX_WITHDRAW As Integer = 200
' Constructor
Public Sub New(initialbalance As Double)
Me.balance = initialbalance
End Sub
' Reuturns current balance
Public Function GetBalance() As Double
Return balance
End Function
' Depost amount to account, if amount is valid
Public Sub Deposit(amount As Double)
' Validate if valid amount
If amount <= 0 Then
Console.WriteLine("Invalid amount, should be greater than 0")
ElseIf amount > MAX_DEPOSIT Then
Console.WriteLine("Deposit of more than " + MAX_DEPOSIT.ToString("c") + " is not allowed")
Else
balance += amount
Console.WriteLine("Deposit Transaction successful")
End If
End Sub
' Withdraw amount from account, if amount is valid
Public Sub Withdraw(amount As Double)
' Validate if valid amount
If amount <= 0 Then
Console.WriteLine("Invalid amount, should be greater than 0")
ElseIf amount > MAX_WITHDRAW Then
Console.WriteLine("Withdrawing more than " + MAX_WITHDRAW.ToString("c") + " is not allowed")
ElseIf amount > balance Then
Console.WriteLine("Insufficient balance!")
Else
balance -= amount
Console.WriteLine("Withdraw Transaction Successful.")
End If
End Sub
End Class
**************************************************************************************************************
TestDriver
Module Module1
Sub Main()
'Pretend you have an initial deposit of 1000.00. You will
Dim atm As ATM = New ATM(1000)
'Prompt the user with a Main menu
Dim displayMenu As Boolean = True
Dim choice As Integer
Dim amount As Double
Do While displayMenu
' get user choice
choice = GetUserMainChoice()
Select Case choice
' Deposit
Case 1
Console.WriteLine("Enter the amount to Deposit")
amount = GetAmount()
' Call deposit method
atm.Deposit(amount)
displayMenu = GetSubMenuChoice()
' withdraw
Case 2
Console.WriteLine("Enter the amount to Withdraw")
amount = GetAmount()
atm.Withdraw(amount)
displayMenu = GetSubMenuChoice()
' Display balanace
Case 3
Console.WriteLine("Your Current Balance = " + atm.GetBalance().ToString("c"))
displayMenu = GetSubMenuChoice()
' quit
Case 4
displayMenu = False
' for invalid choice
Case Else
Console.WriteLine("Invalid Transaction Requested")
displayMenu = GetSubMenuChoice()
End Select
Loop
Console.ReadKey()
End Sub
Public Function GetUserMainChoice() As Integer
' Display menu items
Console.WriteLine("Enter 1 To deposit")
Console.WriteLine("Enter 2 to Withdraw")
Console.WriteLine("Enter 3 to Print Balance")
Console.WriteLine("Enter 4 to quit")
' Get user choice
Dim choice As Integer
Integer.TryParse(Console.ReadLine(), choice)
Return choice
End Function
Public Function GetSubMenuChoice() As Boolean
Dim validInput As Boolean = True
Dim choice As Integer
Do While validInput
Console.WriteLine("Enter 1 to Main Menu")
Console.WriteLine("Enter 2 to Quit")
' verify if valid value is entered
If (Integer.TryParse(Console.ReadLine(), choice) = False Or choice <= 0 Or choice > 2) Then
Console.WriteLine("Invalid Transaction Requested")
Else
' if valid choice
Return choice = 1
End If
Loop
End Function
Public Function GetAmount() As Double
' Get user choice
Dim choice As Double
Double.TryParse(Console.ReadLine(), choice)
Return choice
End Function
End Module
**************************************************************************************************************
Sample Run:
**************************************************************************************
Feel free to rate the answer and comment your questions, if you have any.
Please upvote the answer and appreciate our time.
Happy Studying!!!
**************************************************************************************