I have here my assignment can any one teach me please

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Is to compute for the discount of the two variables of TODDLER and KID

  1. Relevant commands, code, scripts, algorithms:

Im newbie i dont know T_T

The group F4 and their girlfriend San Chai plans to open a
children�s play area in SM City Pines and has asked your help to create a
very simple script to compute for the bill of a customer.

The playground has 2 areas, the KIDS CORNER and the TODDLERS
PLACE. Charging for the first hour on the KIDS CORNER is pegged at PhP
60.00 and PhP 20 for the next 30 minutes. On the other hand, charging for
the first hour on the TODDLERS PLACE is pegged at PhP 40.00 and PhP 15 for
the next 30 minutes. Discounts are available for patrons who have
exceeded 5 hours. Discounts are computed this way :
5 hours to 7 hours = 10 % of total amount due
more than 7 hours to 8 hours = 12 % of total amount due
more than 8 hours = 15 % of total amount due

The script accepts the following arguments :
NAME OF CUSTOMER
TIME IN (actual time of the day the customer entered the
playground followed by either AM or PM)
TIME OUT (actual time of the day the customer moved out of
the playground followed by either AM or PM)
CUSTOMER TYPE (either TODDLER or KID)

The script would output on screen the total number of hours and
minutes the customer used the playground together with the corresponding
charge and discounts( if any). It will also APPEND on a file called
PLAY.REC all of these information.

HINT : you can use the utility expr and control structures like if, for,
case

Sample Run:
$ <your familyname>playground gepaul 10:30 AM 8:30 PM KID

OUTPUT:

F4 and SAN CHAI PLAYGROUND
SM CITY PINES

Jan 15 2012 or system date and time

Name of Customer= gepaul
Customer Type= KID
TIME IN = 10:30 AM
TIME OUT= 8:30 PM

TIME SPENT: 10 hours 0 minutes
CHARGES: 420.00
DISCOUNT: 63.00
AMT. TO PAY: 357.00

thank you for patronage! pls. come again!

  1. The attempts at a solution (include all code and scripts):

Im newbie i dont know T_T

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    University of California, New york, United States, Mr. Alcalde, IT222

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Understand the code first. Don't blindly copy-paste it in your assignment. And I've not included codes for error-handling. Try that yourself.

#! /bin/bash

time_diff () {
    t1=`date -d "$t_in" +%s`
    t2=`date -d "$t_out" +%s`
    t_diff=$((($t2 - $t1) / 60))
    hours=$(($t_diff / 60))
    mins=$(($t_diff % 60))
}

calc_price () {
    case $cust in
    "KID" )
        if [ $hours -gt 1 ]
        then
            if [ $mins -eq 0 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20)))
            elif [ $mins -gt 0 -a $mins -le 30 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20) + 20))
            elif [ $mins -gt 30 -a $mins -lt 60 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20) + 40))
            fi
        else
            price=60
        fi
        ;;
    "TODDLER" )
        if [ $hours -gt 1 ]
        then
            if [ $mins -eq 0 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20)))
            elif [ $mins -gt 0 -a $mins -le 30 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20) + 20))
            elif [ $mins -gt 30 -a $mins -lt 60 ]
            then
                price=$((60 + (($hours - 1) * 2 * 20) + 40))
            fi
        else
            price=40
        fi
        ;;        
    esac
}

calc_discount () {
    if [ $t_diff -lt 300 ]
    then
        discount=0
    elif [ $t_diff -ge 300 -a $t_diff -le 420 ]
    then
        discount=`echo "scale=2; $price * 10 / 100" | bc`
    elif [ $t_diff -gt 420 -a $t_diff -le 480 ]
    then
        discount=`echo "scale=2; $price * 12 / 100" | bc`
    elif [ $t_diff -gt 480 ]
    then
        discount=`echo "scale=2; $price * 15 / 100" | bc`
    fi
    total=`echo "$price - $discount" | bc`
}

echo -e "Enter name: \c"
read name
echo -e "Customer Type: \c"
read cust
echo -e "Time In: \c"
read t_in
echo -e "Time Out: \c"
read t_out

time_diff
calc_price
calc_discount

echo >> PLAY.REC
echo "Name of Customer: $name" >> PLAY.REC
echo "Customer Type: $cust" >> PLAY.REC
echo "Time In: $t_in" >> PLAY.REC
echo "Time Out: $t_out" >> PLAY.REC
echo >> PLAY.REC
echo "Time Spent: $hours hours $mins minutes"
echo "Time Spent: $hours hours $mins minutes" >> PLAY.REC
echo "Charges: $price"
echo "Charges: $price" >> PLAY.REC
echo "Discount: $discount"
echo "Discount: $discount" >> PLAY.REC
echo "Amount to pay: $total"
echo "Amount to pay: $total" >> PLAY.REC
echo "-----------------------------------------------------------"
echo "-----------------------------------------------------------" >> PLAY.REC
1 Like

sir in case of i have another clarifications, can i know your contact please...

You may post your queries here. Members of this forum would help you out. And why did you delete your first post? Other members wouldn't understand the head and tail of this thread now, would they?