February 6th, 2013, 07:56 PM
Need some help
can someone help me here?
Create a script that computes for the total parking charge of a customer.
The following information are to be collected as inputs from the standard input:
Plate number (format: 7 characters, the first 3 are characters from A to Z followed by a dash followed by a 3 digit number; i.e.: XXX-123)
Time in (format: military time; i.e. 1500 => 3 PM)
Time out (format: military time; i.e. 1900 => 7 PM)
Type of vehicle: can either be the following characters:
L, U or H which stands for Light vehicle, Utility vehicle or heavy vehicle respectively.
The parking lot operates starting at 7 AM and closes at 11:30 PM.
The rates in the parking lot are as follows:
Standard parking fee (minimum of 2 hours) = 50 pesos
Succeeding hour or less in excess of 2 hours for:
Light vehicles = 5 pesos
Utility vehicles = 15 pesos
Heavy vehicles = 25 pesos
Furthermore, the maximum parking charge for the following vehicles applies:
Light vehicles = 100 pesos
Utility vehicles = 150 pesos
Heavy vehicles =250 pesos
The script should be able to validate whether the time in and time out values are VALID inputs based on the value that is entered (time out > time in, digits only). Other validations are not to be filtered by the script. The output of the script is the parking charge of the vehicle and its details.
Sample run 1: [prompt]$ <your familyname>parkingbill
Enter the plate number (i.e.: AAE-775): XNY-123
Enter the type of vehicle (L/U/H): U
Enter the time the vehicle entered the parking lot: 0845
Enter the time the vehicle entered the parking lot: 1915
The vehicle with plate number XNY-123 was parked for 10 hours and 30 minutes. The parking charge for the vehicle is 150 pesos
Try again Y/N? N
Sample run 2: [prompt]$ <your family name>parkingbill
Enter the plate number (i.e.: AAE-775): GMA-111
Enter the type of vehicle (L/U/H): L
Enter the time the vehicle entered the parking lot: 1245
Enter the time the vehicle entered the parking lot: 1315
The vehicle with plate number XNY-123 was parked for 0 hours and 30 minutes. The parking charge for the vehicle is 50 pesos
Try again Y/N? N
and this is my unfinish code. ====>
while test "$loop" = "y"
tput cup 1 1; echo -n "Enter the plate number (i.e: AAE-775):"
tput cup 1 40; read plate
if [[ !($platenum != [A-Z][A-Z][A-Z]-[0-9][0-9][0-9]) ]];
tput cup 2 1; echo "Enter the type of vehicle ([L]/[U]/[H]);"
else echo -n "INVALID PLATE NUMBER!"
tput cup 2 42; read type
if [[ !($type != [L]) ]] || [[ !(type != [U]) ]];
tput cup 3 1; echo "Enter the time the vehicle entered the parking lot:"
tput cup 3 1; echo "Enter the time the vehicle exited the parking lot:'
else echo -n "INVALID TYPE!"
tput cup 3 55; read timein;
tput cup 4 55; read timeout;
let timet=$[timein + timeout];
tput cup 6 1; echo -n "The vehicle with plate number $platenum was parked for $timet :"
tput cup 7 1; echo -n "Try again y/n?:"
tput cup 7 16; read loop
if test "$loop" = "n"
clear ; exit
February 7th, 2013, 04:11 PM
Originally Posted by prince13
You may need to use awk to do the hour/minute computations.
Otherwise, I personally would not use "ksh" shell to develop an application.
February 9th, 2013, 06:24 AM
Pretty much my thought!
As a sugegstion - don't have double negative conditional statements ... if not x not y type stuff gets confusing to follow!
Also once you spot a 'fail' on input you should halt or go back to start, not continue.
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc