Computer Science, asked by abhinavraj0001, 1 year ago

write a program in java to calculate the telephone bills as per the instructions below

First 100 calls for Rs 100
Additional 50 calls Rs 50 per calls
and for more than 150 Rs1.50 per call.......

Answers

Answered by prashilpa
58

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());

   }

}

Similar questions