-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsortwage2.sh
50 lines (41 loc) · 881 Bytes
/
sortwage2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash -x
# constants
EMP_RATE_PER_HR=20
IS_FULLTIME=1
IS_PARTTIME=2
NUM_OF_WORKING_DAYS=10
MAX_HRS_IN_MONTH=25
# variables
totalEmpHrs=0
totalworkingDays=0
declare -A dailywage
function getworkingHours() {
case $1 in
$IS_FULLTIME)
empHrs=8
;;
$IS_PARTTIME)
empHrs=4
;;
*)
empHrs=0
;;
esac
echo $empHrs
}
function calculatewage() {
empHrs=$1
wage=$(($empHrs*$EMP_RATE_PER_HR))
echo $wage
}
while [[ $totalEmpHrs -lt $MAX_HRS_IN_MONTH && $totalworkingDays -lt $NUM_OF_WORKING_DAYS ]]
do
((totalworkingDays++))
empcheck=$((RANDOM%3))
workHrs="$( getworkingHours $empcheck )"
totalEmpHrs=$(($totalEmpHrs+$workHrs))
dailywage["Day"$totalworkingDays]="$( calculatewage $workHrs )"
done
salary=$(($totalEmpHrs*$EMP_RATE_PER_HR))
echo ${dailywage[@]}
echo ${!dailywage[@]}