Java Program to Calculate the 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 the following criteria:

If the customer made less than 60 minutes of calls, then he or she also has to pay $14, even if he or 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 the previous month based on the total number of minutes of calls made. Here is its answer: This program follows the rates given above.

import java.util.Scanner;

public class CodesCracker
{
   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 the total minutes of calls made:

java calculate telephone bill

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

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

import java.util.Scanner;

public class CodesCracker
{
   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 a 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 showing how the monthly telephone bills can be calculated using a Java program.

Java Online Test


« Previous Program Next Program »


Liked this post? Share it!