a JAVAScript programs on nested if control structure
Write a program to computerize the billing operation of a
Electricity of Reliance Energy Pvt. Ltd. .The bill has to be generated
based on the following conditions:
Electricity of Reliance Energy Pvt. Ltd. .The bill has to be generated
based on the following conditions:
Number of unit Amount per unit
First 100 units 40 paise per unit
Next 200 units 60 paise per unit
More than 300 units 1 Re per unit
A rent of Rs 205 is charged from every customer. Print the bill for a customer.
Solution:-
<html>
<head><title>if condition</title>
</head>
<script Language="JavaScript">
var name,pv,pr,units,c,net;
name=prompt("Please enter the name of the customer ");
document.write("The customer is:",name);
document.write("<br>");
pv=prompt("Please enter the previous units of the customer ");
document.write("Previous units:",pv);
document.write("<br>");
pr=prompt("Please enter the present units of the customer ");
document.write("Present units:",pr);
document.write("<br>");
units=pr-pv;
if(units<=100)
{
c=units*0.40;
}
else if(units<=300)
{
c=100*0.40+(units-100)*0.60;
}
else
{
c=100*0.40+200*0.60+(units-300)*1;
}
net=c+205;
document.write("units consumed:",units);
document.write("<br>");
document.write("The charge is :",c);
document.write("<br>");
document.write("The net charge is",net);
</script><br><br><br>
</body>
</html>
b) In Karthika High School and Jr College Grades for Students is computed based on the following conditions:
Percentage of marks Grade
More than 74 Distinction
60 to 74 A Grade
50 to 59 B Grade
35 to 49 C Grade
Less than 35 Fail
Write a program in JavaScript which will accept the Marks and calculate their Grade.
Solution:-
<html>
<head><title>if condition</title>
</head>
<body>
<script Language="JavaScript">
var rno;
var name;
var marks;
var gr;
rno=prompt("Please enter your rollno");
name=prompt("Please enter your name");
marks=prompt("Please enter your marks");
if(marks>=75)
{
gr="Distinction"
alert("Congratulations you got distinction");
}
else if(marks>=60)
{
gr="A"
alert("Your grade is A");
}
else if(marks>=50)
{
gr="B"
alert("Your grade is B");
}
else if(marks>=35)
{
gr="C"
alert("Your grade is c");
}
else
{
gr="Failed"
alert("Disastrous !!!!you Failed , you duffer");
}
document.write("Roll nO:",rno);
document.write("<br>");
document.write("Name of the student:",name);
document.write("<br>");
document.write("Your Grade :",gr);
</script></body>
</html>
c) Computer dealer sells computers at the following rates
[i] Rs.31500 per computer less than 20 computers
[ii] Rs.31000 per computer 20 to 39 computers
[iii] Rs.29000 per computer for 40 or more computers
Write a program to take the number of computer as input and display the bill.
Solution:_
<html>
<head><title>Computer dealer</title></head>
<body bgcolor="tan">
<script language="JavaScript">
var qty,amount;
qty=prompt("Please enter the number of computers purchased");
if(qty<=20)
{
amount=qty*31500;
}
else if(qty<40)
{
amount=qty*31000;
}
else if(qty>=40)
{
amount=qty*29000;
}
document.write("number of computers=",qty);
document.write("<br>");
document.write("Net amount to pay=",amount);
</script>
</body>
</html>
d) In an organization, the Income Tax for employees is computed as per the following slab rates:
Slabs (Taxable Income) Rate of Income Tax
Upto Rs 1,10,000 Nil
Rs 1,10,001 to Rs 1,50,000 10% of income exceeding Rs 1,10,000
Rs 1,50,001 to Rs 2,50,000 Rs 4,000 + 20% of income exceeding Rs 1,50,000
Above Rs 2,50,000 Rs 24,000 + 30% of income exceeding Rs 2,50,000
Write a program in JavaScript which will accept the income and calculate their income tax.
Write a program in JavaScript which will accept the income and calculate their income tax.
Solution:-
<html>
<head><title>income tax</title></head>
<body bgcolor="tan">
INCOME TAX OF INDIA<br>
<script language="JavaScript">
var income=prompt("please enter your income");
var tax;
if(income<=110000)
{
tax=0;
}
else if(income<=150000)
{
tax=0.10*(income-110000);
}
else if(income<=250000)
{
tax=4000+0.20*(income-150000);
}
else if(income>250000)
{
tax=24000+0.30*(income-250000);
}
document.write("Your Income is=",income);
document.write("<br>");
document.write("Your tax amount=",tax);
</script>
</body>
</html>
e) Write a program to calculate the charge of a parcel taking weight of the parcel as input.
Sample Input: Weight of the parcel =180gms
Charge : for 100gms =30Rs
for next 50gms =10Rs
for remaining 30gms =10Rs
Sample Output: Total Charge:Rs 50
Solution:-
<html>
<head><title>Parcel</title></head>
<body>
<script language="JavaScript">
var wt,rate;
wt=prompt("please enter the weight of parcel");
if(wt<=100)
{
rate=30;
}
else if(wt<=150)
{
rate=30+10;
}
else if(wt<=180)
{
rate=30+10+10;
}
else if(wt>180)
{
rate=60;
}
document.write("your parcel Weight=",wt);
document.write("<br>");
document.write("Amount to pay=",rate);
</script>
</body>
</html>
f) A cloth showroom has announced the following festival discounts on the purchase of items, based on the
Total cost of the items purchased :- Total Cost Discount (in percentage)
Less than Rs. 2000 5%
Rs. 2001 to Rs. 5000 25%
Rs. 5001 to Rs. 10000 35%
Above Rs. 10000 50%
Write a program to input the total cost and to compute and display the amount to be paid by the customer
After availing the discount.
Solution:-
<html>
<head><title>Showroom Discount</title></head>
<body>
<script language="JavaScript">
var c,d;
c=prompt("please enter your cost");
if(c<=2000)
{
d=(5/100)*c;
}
else if(c<=5000)
{
d=25/100*c;
}
else if(c<=10000)
{
d=35/100*c;
}
else if(c>=10000)
{
d=50/100*c;
}
document.write("Your cost of the cloth=",c);
document.write("<br>");
document.write("! you have a discount of Rs=",d);
</script>
</body>
</html>
g) Write a program to computerize the billing operation of a telephone of a telephone company .The bill has to be generated based on the following conditions: Number of calls Amount per call
First 50 calls free
Next 100 calls 50 P per call
Next 200 calls 80 P per call
Rest of the calls Rs 1.20 per call
A rent of Rs 120 is charged from every customer. A tax of 15% is charged on the sum of charges and rent. The total amount is tax added to the sum of charges and rent .Print the bill for a customer.
First 50 calls free
Next 100 calls 50 P per call
Next 200 calls 80 P per call
Rest of the calls Rs 1.20 per call
A rent of Rs 120 is charged from every customer. A tax of 15% is charged on the sum of charges and rent. The total amount is tax added to the sum of charges and rent .Print the bill for a customer.
Solution:-
<html>
<head><title>simple</title></head>
<body>
<script language="JavaScript">
var n,ch,net;
n=prompt("please enter the number of calls");
if(n<=50)
{
ch=0
}
else if(n<=150)
{
ch=0.50*(n-50);
}
else if(n<=350)
{
ch=(100*0.50)+0.80*(n-150);
}
else
{
ch=(100*0.50)+(0.80*200)+(1.20*(n-350));
}
document.write("your number of calls=",n);
document.write("<br>")
document.write("your cost=",ch);
</script>
</body>
</html>
No comments:
Post a Comment