billing(Customer_ID,Kwh,Amount) :- customer(Customer_ID,Customer_Kind,Customer_Type,Territory), print('customer_ID: ',Customer_ID), print('customer_kind: ',Customer_Kind), print('customer_type: ',Customer_Type), print('territory; ',Territory), bill(Customer_Kind,Customer_Type,Territory,Kwh,Amount),!. % normal residential customers bill(residential,normal,Territory,Kwh,Amount) :- current_season(Season), residential_rate(Territory,Season,Rate), Amount is Kwh * Rate. % lifeline residential customers bill(residential,lifeline,Territory,Kwh,Amount) :- Kwh <= 100, Amount is Kwh * 3,!. bill(residential,lifeline,Territory,Kwh,Amount) :- Kwh <= 200, Amount is 300 + (Kwh - 100) * 5,!. bill(residential,lifeline,Territory,Kwh,Amount) :- Kwh > 200, bill(residential,normal,Territory,Kwh,Amount),!. % business customers bill(business,_,_,Kwh,Amount) :- Kwh <= 1000, Amount is Kwh * (9 - Kwh / 500),!. bill(business,_,_,Kwh,Amount) :- Kwh > 1000, Amount is 7000 + (Kwh - 1000) * 5,!. % industrial customers bill(industrial,any_interrupt,_,Kwh,Amount) :- bill(business,_,_,Kwh,BusBill), Discount is BusBill / 5, Amount is BusBill - Discount,!. % discount(20),!. bill(industrial,one_hour_interrupt,_,Kwh,Amount) :- bill(business,_,_,Kwh,BusBill), Discount is BusBill / 10, Amount is BusBill - Discount,!. % discount(10),!, bill(industrial,two_hour_interrupt,_,Kwh,Amount) :- bill(business,_,_,Kwh,BusBill), Discount is BusBill / 20, Amount is BusBill - Discount,!. % discount(5),!, bill(industrial,none,_,Kwh,BusBill) :- bill(business,_,_,Kwh,BusBill),!. % test database % customer(Customer_ID,Customer_Kind,Customer_Type,Territory). customer(tom,residential,normal,terr_1). customer(joe,residential,lifeline,terr_1). customer(bell,business,_,_). customer(factory1,industrial,any_interrupt,_). % current_season(Season). current_season(summer). % residential_rate(Territory,Season,Rate). residential_rate(terr_1,summer,6). residential_rate(terr_1,winter,7). residential_rate(terr_2,summer,7). residential_rate(terr_2,winter,6). residential_rate(terr_3,_,6). test(Amount) :- billing(joe,500,Amount).