Calculating Mobile Bill Cost – Java Program

What it does: 

A simple Java program to calculate the cost of a mobile phone bill. A text costs 0.25, a call is 0.10 a minute and when the phone bill total is more than 15 there is a 20% discount applied.

Code: 

</pre>
import java.text.DecimalFormat;
import java.util.Scanner;

public class MobileCost
{
 public static void main(String[] args)
 {
 Scanner keyboard = new Scanner(System.in);
 DecimalFormat df = new DecimalFormat("0.00");

final double TEXTCOST = 0.25;
 final double CALLCOST = 0.10;
 final double DISCOUNT = 0.20;

int textUsed;
 double callUsed, totalForCall, totalForText, totalTogether, totalDiscount, finalTotalForDis;

System.out.println("Please enter the number of minutes you have used");
 callUsed =keyboard.nextDouble();

System.out.println("Please enter the number of text you have used");
 textUsed = keyboard.nextInt();

totalForCall = callUsed*CALLCOST;
 totalForText = textUsed*TEXTCOST;

totalTogether = totalForCall+totalForText;

totalDiscount = totalTogether*DISCOUNT;
 finalTotalForDis = totalTogether-totalDiscount;

if (totalTogether >=15)

{
 System.out.println("The number of texts you have used is " + df.format(textUsed));
 System.out.println("The number of minutes you have used is " + df.format(callUsed));

System.out.println("Your discount is " + df.format(totalDiscount));

System.out.println("You final total is " + df.format(finalTotalForDis));
 }//if

else
 {
 System.out.println("The number of texts you have used is " + df.format(textUsed));
 System.out.println("The number of minutes you have used is " + df.format(callUsed));

System.out.println("Your not entitled to discount this time");

System.out.println("Your total bill is " + df.format(totalTogether));
 }//else
 }//main
}//class
<pre>

 

One thought on “Calculating Mobile Bill Cost – Java Program

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s