Write four shell scripts called atm.bash (in Bourne Again shell) , atm.ksh (in K
ID: 3850924 • Letter: W
Question
Write four shell scripts called atm.bash (in Bourne Again shell), atm.ksh (in Korn shell) and atm.csh (in C shell) and atm.zsh (in Z shell) similar to the ones used in ATM machines. Essentially your script is to handle a person's savings and checking accounts and should handle the following services:
Transfer from savings account to checking account
Transfer form checking account to savings account
Cash withdrawal from either account
Balance statements for both the accounts
Assume that the ATM machine recognizes a unique 3-digit personal identification number (PIN). In your initial screen you are to first ask the user to type in his/her PIN as follows:
*** Welcome to the ATM ****
Please enter your PIN:
In response to this, the user has to enter a valid PIN. Assume that the only legal PIN is: 111
If any number besides this PIN is entered, the screen is to be cleared and the same screen to be redisplayed. The user then gets a second chance to enter a valid PIN. If an illegal PIN is entered three consecutive times, the following message:
Too many illegal PINs. Try later again.
should appear on the screen and your script must terminate. If the entered PIN is a legal value, the main menu is to be displayed as follows:
*** Welcome to the ATM System ***
(1) Transfer from checking account to savings account
(2) Transfer from savings account to checking account
(3) Savings account balance
(4) Checking account balance
(5) Withdraw Cash from either account
(6) Exit
==> Please select option (1-6):
The following are some of the guidelines you should follow:
Guidelines
-- The main menu is to continue to be displayed until user selects option 6. At this point a message such as
Thank you for using the ATM system.
should appear and your program execution is to be terminated.
-- Users have to select options 1, 2, 3, 4, 5 or 6. Redisplay the menu if any number outside the range 1 to 6 is entered (Hint: Use the command clear after every menu option is complete and before displaying the menu again)
-- Write functions (if the shell allows for user defined functions) for menu options for transferring and withdrawing from the accounts.
-- Withdrawal (selection 5) should ask whether the user wants to withdraw from checking account or saving account and should subtract the amount specified from the appropriate account.
-- Savings and checking accounts both have initial balance of $1000.00
-- Any transfer is allowed only if it can be honored. For example, if the savings account balance is $500.00 and the user requests to transfer $550.00 from that savings account to the checking account an appropriate message such as
"Transaction not completed"
should be displayed and the current balance of that account should be printed.
The screen is to be cleared and the main menu to be displayed.
Explanation / Answer
To solve this problem saving amount and checking amount is taken 1000 and 1000 respectiely. you can change tthem based on tour cases -
(1)
The program in Bourne Again Shell.
The file name is atm.bash and you can provide any other name with .bash extension.
to compile in terminal follow command -> chmod +x atm.bash
to execute follow command -> ./atm.bash
code is written here
#!/bin/bash
echo "Welcome to the ATM"
code=123
savingamount=1000
checkingamount=1000
again=1
echo "Enter your 3 digit pin"
read pin
if [ $pin -eq $code ]
then
while [ $again -eq 1 ]
do
echo "Select one choice enter 1 , 2 , 3 , 4 , 5 , 6 "
echo "(1) Transfer from checking account to savings account"
echo "(2) Transfer from savings account to checking account"
echo "(3) Savings account balance"
echo "(4) Checking account balance"
echo "(5) Withdraw Cash from either account"
echo "(6) Exit"
echo "Enter an Option"
read op
case $op in
1)
echo "you have selected transfer from checking account to savings account "
echo "entert amount "
read a
if [ $a -le $checkingamount ]
then
echo "$a is transferred from checking account to saving account"
checkingamount=` expr $checkingamount - $a `
savingamount=` expr $savingamount + $a `
else
echo "Can't be done Low Balance in checking account"
fi
;;
2)
echo "you have selected transfer from checking account to saving account "
echo "entert amount "
read b
if [ $b -le $savingamount ]
then
echo "$a is transferred from saving account to checking account"
savingamount=` expr $savingamount - $b `
checkingamount=` expr $checkingamount + $b `
else
echo "Can't be done Low Balance in saving account"
fi
;;
3)
echo "Saving account balance is "
echo $savingamount
;;
4)
echo "Checking account balance is"
echo $checkingamount
;;
5)
echo "Withdraw case from either account"
echo "Select 1 for saving account and 2 for checking account"
read ch
echo "Enter amount to witdraw"
read c
if [ $ch -eq 1 ]
then
if [ $savingamount -lt $c ]
then
echo "Not sufficient Balance in saving account"
else
echo "Amount $c is withdrawn "
savingamount=` expr $savingamount - $c `
echo "Current Balance in saving account is " $savingamount
fi
fi
if [ $ch -eq 2 ]
then
if [ $checkingamount -lt $c ]
then
echo "Not sufficient Balance in checking account"
else
echo "Amount $c is withdrawn "
checkingamount=`expr $checkingamount - $c `
echo "Current Balance is checking amount is " $checkingamount
fi
fi
;;
6) echo "You are done Thanks for using ATM"
exit
;;
*)
echo "You didn't select a valid choice try again"
esac
echo "Want to Conitnue ? Enter 1 to continue and 0 to exit "
read e
if [ $e -eq 1 ]
then
again=`expr $e `
else
exit
fi
done
else
echo "Entered pin number is wrong "
fi
(2) Script in Korn Shell
Here the program is written in Korn shell
The name of the file is atm.ksh you can provide any other name with .ksh extension
to have the permission to execute follow command -> chmod +x atm.ksh
to get output follow command -> ./atm.ksh
Please note the instructions carefully in the output .
#!/bin/bash
echo "Welcome to the ATM"
code=123
savingamount=1000
checkingamount=1000
again=1
echo "Enter your 3 digit pin"
read pin
if [ $pin -eq $code ]
then
while [ $again -eq 1 ]
do
echo "Select one choice enter 1 , 2 , 3 , 4 , 5 , 6 "
echo "(1) Transfer from checking account to savings account"
echo "(2) Transfer from savings account to checking account"
echo "(3) Savings account balance"
echo "(4) Checking account balance"
echo "(5) Withdraw Cash from either account"
echo "(6) Exit"
echo "Enter an Option"
read op
case $op in
1)
echo "you have selected transfer from checking account to savings account "
echo "entert amount "
read a
if [ $a -le $checkingamount ]
then
echo "$a is transferred from checking account to saving account"
checkingamount=` expr $checkingamount - $a `
savingamount=` expr $savingamount + $a `
else
echo "Can't be done Low Balance in checking account"
fi
;;
2)
echo "you have selected transfer from checking account to saving account "
echo "entert amount "
read b
if [ $b -le $savingamount ]
then
echo "$a is transferred from saving account to checking account"
savingamount=` expr $savingamount - $b `
checkingamount=` expr $checkingamount + $b `
else
echo "Can't be done Low Balance in saving account"
fi
;;
3)
echo "Saving account balance is "
echo $savingamount
;;
4)
echo "Checking account balance is"
echo $checkingamount
;;
5)
echo "Withdraw case from either account"
echo "Select 1 for saving account and 2 for checking account"
read ch
echo "Enter amount to witdraw"
read c
if [ $ch -eq 1 ]
then
if [ $savingamount -lt $c ]
then
echo "Not sufficient Balance in saving account"
else
echo "Amount $c is withdrawn "
savingamount=` expr $savingamount - $c `
echo "Current Balance in saving account is " $savingamount
fi
fi
if [ $ch -eq 2 ]
then
if [ $checkingamount -lt $c ]
then
echo "Not sufficient Balance in checking account"
else
echo "Amount $c is withdrawn "
checkingamount=`expr $checkingamount - $c `
echo "Current Balance is checking amount is " $checkingamount
fi
fi
;;
6) echo "You are done Thanks for using ATM"
exit
;;
*)
echo "You didn't select a valid choice try again"
esac
echo "Want to Conitnue ? Enter 1 to continue and 0 to exit "
read e
if [ $e -eq 1 ]
then
again=`expr $e `
else
exit
fi
done
else
echo "Entered pin number is wrong "
fi
(3)
Here the program is written in C shell
The name of the file is atm.csh you can provide any other name with .csh extension
to have the permission to execute follow command -> chmod +x atm.csh
to get output follow command -> ./atm.csh
Please note the instructions carefully in the output .
#!/bin/bash
echo "Welcome to the ATM"
code=123
savingamount=1000
checkingamount=1000
again=1
echo "Enter your 3 digit pin"
read pin
if [ $pin -eq $code ]
then
while [ $again -eq 1 ]
do
echo "Select one choice enter 1 , 2 , 3 , 4 , 5 , 6 "
echo "(1) Transfer from checking account to savings account"
echo "(2) Transfer from savings account to checking account"
echo "(3) Savings account balance"
echo "(4) Checking account balance"
echo "(5) Withdraw Cash from either account"
echo "(6) Exit"
echo "Enter an Option"
read op
case $op in
1)
echo "you have selected transfer from checking account to savings account "
echo "entert amount "
read a
if [ $a -le $checkingamount ]
then
echo "$a is transferred from checking account to saving account"
checkingamount=` expr $checkingamount - $a `
savingamount=` expr $savingamount + $a `
else
echo "Can't be done Low Balance in checking account"
fi
;;
2)
echo "you have selected transfer from checking account to saving account "
echo "entert amount "
read b
if [ $b -le $savingamount ]
then
echo "$a is transferred from saving account to checking account"
savingamount=` expr $savingamount - $b `
checkingamount=` expr $checkingamount + $b `
else
echo "Can't be done Low Balance in saving account"
fi
;;
3)
echo "Saving account balance is "
echo $savingamount
;;
4)
echo "Checking account balance is"
echo $checkingamount
;;
5)
echo "Withdraw case from either account"
echo "Select 1 for saving account and 2 for checking account"
read ch
echo "Enter amount to witdraw"
read c
if [ $ch -eq 1 ]
then
if [ $savingamount -lt $c ]
then
echo "Not sufficient Balance in saving account"
else
echo "Amount $c is withdrawn "
savingamount=` expr $savingamount - $c `
echo "Current Balance in saving account is " $savingamount
fi
fi
if [ $ch -eq 2 ]
then
if [ $checkingamount -lt $c ]
then
echo "Not sufficient Balance in checking account"
else
echo "Amount $c is withdrawn "
checkingamount=`expr $checkingamount - $c `
echo "Current Balance is checking amount is " $checkingamount
fi
fi
;;
6) echo "You are done Thanks for using ATM"
exit
;;
*)
echo "You didn't select a valid choice try again"
esac
echo "Want to Conitnue ? Enter 1 to continue and 0 to exit "
read e
if [ $e -eq 1 ]
then
again=`expr $e `
else
exit
fi
done
else
echo "Entered pin number is wrong "
fi
(4)
Here the script is written in Z shell
The name of the file is atm.zsh you can provide any other name with .zsh extension
to have the permission to execute follow command -> chmod +x atm.zsh
to get output follow command -> ./atm.zsh
Please note the instructions carefully in the output .
#!/bin/bash
echo "Welcome to the ATM"
code=123
savingamount=1000
checkingamount=1000
again=1
echo "Enter your 3 digit pin"
read pin
if [ $pin -eq $code ]
then
while [ $again -eq 1 ]
do
echo "Select one choice enter 1 , 2 , 3 , 4 , 5 , 6 "
echo "(1) Transfer from checking account to savings account"
echo "(2) Transfer from savings account to checking account"
echo "(3) Savings account balance"
echo "(4) Checking account balance"
echo "(5) Withdraw Cash from either account"
echo "(6) Exit"
echo "Enter an Option"
read op
case $op in
1)
echo "you have selected transfer from checking account to savings account "
echo "entert amount "
read a
if [ $a -le $checkingamount ]
then
echo "$a is transferred from checking account to saving account"
checkingamount=` expr $checkingamount - $a `
savingamount=` expr $savingamount + $a `
else
echo "Can't be done Low Balance in checking account"
fi
;;
2)
echo "you have selected transfer from checking account to saving account "
echo "entert amount "
read b
if [ $b -le $savingamount ]
then
echo "$a is transferred from saving account to checking account"
savingamount=` expr $savingamount - $b `
checkingamount=` expr $checkingamount + $b `
else
echo "Can't be done Low Balance in saving account"
fi
;;
3)
echo "Saving account balance is "
echo $savingamount
;;
4)
echo "Checking account balance is"
echo $checkingamount
;;
5)
echo "Withdraw case from either account"
echo "Select 1 for saving account and 2 for checking account"
read ch
echo "Enter amount to witdraw"
read c
if [ $ch -eq 1 ]
then
if [ $savingamount -lt $c ]
then
echo "Not sufficient Balance in saving account"
else
echo "Amount $c is withdrawn "
savingamount=` expr $savingamount - $c `
echo "Current Balance in saving account is " $savingamount
fi
fi
if [ $ch -eq 2 ]
then
if [ $checkingamount -lt $c ]
then
echo "Not sufficient Balance in checking account"
else
echo "Amount $c is withdrawn "
checkingamount=`expr $checkingamount - $c `
echo "Current Balance is checking amount is " $checkingamount
fi
fi
;;
6) echo "You are done Thanks for using ATM"
exit
;;
*)
echo "You didn't select a valid choice try again"
esac
echo "Want to Conitnue ? Enter 1 to continue and 0 to exit "
read e
if [ $e -eq 1 ]
then
again=`expr $e `
else
exit
fi
done
else
echo "Entered pin number is wrong "
fi
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.