Write a java program to calculate the bill amount to be paid by a customer based on the following category by taking name and call as input.
Phone calls charge
first 10 Rs. 1 per call
next 15 Rs. 2 per call next 20 Rs. 3 per call above 45 Rs. 4 per call
print output in table format.
Name Calls Bill Amount
________ _______ _________
xx xx xx
" WRITE INPUT, OUTPUT AND VARIABLE DESCRIPTION TABLE ALSO "
Answers
answer:
Self explanatory program given below with comments.
Explanation:
import java.util.Scanner;
public class PhoneBill
{
int calls;
double money;
/* constructor function over loaded to take the number of input calls */
public PhoneBill(){
Scanner s=new Scanner(System.in);
System.out.println(“Enter the number of calls made by customer”);
/* Calls variable holds the number of calls entered */
calls = s.nextInt();
}
/* Method definition of billing */
public double billing()
{
if (calls <= 100) /* Rs. 100 for first 100 calls */
money = 100;
else if (calls > 100) && (calls <= 150)
/* Additional 50 calls also charged at Rs.1 per call */
money = 1*(calls);
else if (calls > 150)
/* After 150 calls , charge Rs. 1.50 per call */
money = 150 + (calls-150)* 1.50;
return money;
}
public static void main(String[] args) {
PhoneBill p = new PhoneBill();
System.out.println(“Bill generated = ”+ p.billing());
}
}