Java Program to Calculate Monthly Telephone Bill

This article contains a program in Java that can calculate and print the monthly telephone call bill. The bill must be generated as per following criteria:

If the customer made less than 60 minutes of call, then also he/she has to pay $14, even if he/she made no calls for that month.

Telephone Bill Program in Java

The question is, write a Java program to find and print the telephone bill that has to be paid for previous month, based on the total minutes of calls made. Here is its answer. This program follows the rates as given above.

import java.util.Scanner;

public class fresherearth
{
   public static void main(String[] args)
   {
      int numberOfCalls;
      float phoneBill;
      Scanner scan = new Scanner(System.in);
      
      System.out.print("Enter the Total Minutes of Calls Made this Month: ");
      numberOfCalls = scan.nextInt();
      
      if(numberOfCalls<=60)
         phoneBill = 14;
      else
      {
         numberOfCalls = numberOfCalls - 60;
         phoneBill = 14 + (float)(numberOfCalls * 0.12);
      }
      
      System.out.println("\nTelephone Bill this Month = " +phoneBill);
   }
}

Here is its sample run with user input 432 as total minutes of calls made:

java calculate telephone bill

The above program is little basic, because some time we need to calculate different rates for different calls. For example, the customer making national calls costs lesser than making international calls. Therefore let's modify the above program, and create another one with following criteria:

Here is the program calculates telephone bill, based on the national and international calls entered by the user:

import java.util.Scanner;

public class fresherearth
{
   public static void main(String[] args)
   {
      int nationalCalls, internationalCalls;
      float phoneBill;
      Scanner scan = new Scanner(System.in);
      
      System.out.print("Enter the Total Minutes of National Calls: ");
      nationalCalls = scan.nextInt();
      System.out.print("Enter the Total Minutes of International Calls: ");
      internationalCalls = scan.nextInt();
      
      if(nationalCalls==0)
         phoneBill = 0;
      else if(nationalCalls<=60)
         phoneBill = 14;
      else
      {
         nationalCalls = nationalCalls - 60;
         phoneBill = 14 + (float)(nationalCalls * 0.12);
      }
	  
      if(internationalCalls==0)
         phoneBill = phoneBill;
      else if(internationalCalls<=12)
         phoneBill = phoneBill + 16;
      else
      {
         internationalCalls = internationalCalls - 12;
         phoneBill = phoneBill + 16 + (float)(internationalCalls * 2.34);
      }
      
      System.out.println("\nTelephone Bill this Month = " +phoneBill);
   }
}

Here is its sample run with user input 289 minutes of national and 68 minutes of international calls:

java program find monthly telephone bill

You can modify the above program and create your required version based on your criteria, as this is just a demo program shows how the monthly telephone bills can be calculated using a Java program.

Java Online Test


« Previous Program Next Program »