You Are Reading

1

Cellphone Bill Computation Program

BufferedReader

Problem:

Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary depending on the type of service. The rates are computed as follows:

Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute.

Premium service: $25.00 plus:

a. For calls made from 6:00 am to 6:00 pm, the first 75 minutes are free.

b. For calls made from 6:00 pm to 6:00 am, the first 100 minutes are free. Charges for over 100 minutes are $0.05 per minute.

Your program should prompt the user to enter an account number, a service code and the number of minutes the service was used. A service code for r or R means regular service, a service code of p or P means premium service. Treat any other character as an error. Your program should output the account number, type of service,

number of minutes the telephone service was used and the amount due from user.

For premium service, the customer may be using the service during the day and the night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes th

e service was used during the night. Format your output to have two decimal places.

Sample Output:

Codes:

package javaapplication1;

import java.io.*;

import java.text.*;

public class num3 {

private static PrintStream p=System.out;

public static BufferedReader q=new BufferedReader (new InputStreamReader (System.in));

public static void main(String[] args)throws IOException {

p.print("Account Number: ");

String an=q.readLine();

int AN=Integer.parseInt(an);

p.println("Service code(Press R or P): \n R-Regular Service \n P-Premium Service");

String sc=q.readLine();

char SC=sc.charAt(0);

DecimalFormat f = new DecimalFormat("#.##");

if (SC=='r' || SC=='R' || SC=='P' || SC=='p')

{

if (SC=='r' || SC=='R')

{

p.print("Number of minutes the service was used: ");

String m=q.readLine();

int M=Integer.parseInt(m);

if (M>50)

{

double c, tm;

tm=M-50;

c= 10.00 + (tm*0.20);

p.println("Amount due: $" +f.format(c));

}

else

{

double amount;

amount=10;

p.println("Amount due: $" +amount);

}

}

else if (SC=='P' || SC=='p')

{

p.print ("Minutes called between 6:00am to 6:00pm: ");

String am=q.readLine();

int AM=Integer.parseInt(am);

double amDue=0, pmDue=0;

if (AM==0)

{

amDue=0;

}

else if(AM <= 75)

{

amDue=25;

}

else

{

double min;

min=AM-75;

amDue=(min*.1)+25;

}

p.print ("Minutes called between 6:00pm to 6:00am: ");

String pm=q.readLine();

int PM=Integer.parseInt(pm);

if (PM==0)

{

pmDue=0;

}

else if (PM <= 100 && PM != 0)

{

pmDue=25.00;

}

else

{

double min2;

min2=PM-100;

pmDue=(min2 * .05)+25;

}

double Totaldue;

Totaldue=amDue+pmDue;

p.println("Total Amount Due: " +f.format(Totaldue));

}

}

else

{

p.println("Invalid input!");

}

}

}

1 comments:

Anonymous said...

I'm actually searching post regarding phone bills. Thanks for sharing those info.

Check this out too:
Medisoft Software

Post a Comment

 
Copyright 2010 BufferedReader