0% found this document useful (0 votes)
10 views1 page

Java Program for Telephone Bill Calculation

The document contains Java code examples demonstrating the calculation of temperature conversion from Fahrenheit to Celsius and the calculation of monthly telephone charges. The telephone charges include a fixed amount and variable charges based on the number of calls made, with different rates applied to different call ranges. The final output of the telephone charges program is the total bill calculated based on the number of calls.

Uploaded by

tushikasahu5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Java Program for Telephone Bill Calculation

The document contains Java code examples demonstrating the calculation of temperature conversion from Fahrenheit to Celsius and the calculation of monthly telephone charges. The telephone charges include a fixed amount and variable charges based on the number of calls made, with different rates applied to different call ranges. The final output of the telephone charges program is the total bill calculated based on the number of calls.

Uploaded by

tushikasahu5
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

class Demo

{
public static void main(string args[])
{
[Link]("Hello")
}
}

class Main
{
public static void main(String args[])
{
double fahrenheit=98.0;
double celsius = (fahrenheit - 32) * 5 / 9;
[Link](celsius);
}
}

WRITE A PROGRAM TO CALCULATE MONTHLY TELEPHONE CHARGES FOR A PERSON CHARGES


CONSISTES OF FIX AMOUNT 250... AND VARIABLE CHARGES BASED ON NUMBER CALL AND
VARIABLE CHARGES CALCULATE AS FOLLOW
0.50 FROM EACH 1ST 100 CALL... 0.60 FOR NEXT 100 CALL... 0.75 FOR REMAINING
CALCULATE TOTAL BILL

class Main
{
public static void main(String args[])
{
int fixed_amt =250;
int calls = 450;
double hcall = 0.50;
double scall = 0.60;
double rcall = 0.75;
double amount = 0.0;
double total_amount;
if (calls <= 100)
amount = calls*hcall;
else if (calls <= 200)
amount = (100*hcall) + (calls-100)*scall;
else
amount = (100*hcall) + (100*scall)+ (calls-200)*rcall;
total_amount=amount+fixed_amt;
[Link](total_amount);
}
}

Common questions

Powered by AI

The code `System.out.Println("Hello")` contains a capitalization error in 'Println' which should be 'println'. Additionally, the keyword 'string' is incorrectly used; it should be 'String' because Java is case-sensitive. The corrected line is: `System.out.println("Hello");`.

The `int calls = 450;` statement declares a local variable `calls` within the main method. It implies that `calls` is accessible only within this method scope and not outside it, as it is not a class variable or global.

The program uses a series of if-else statements to apply billing rates. It calculates charges based on the number of calls. If rates changed to 0.30, 0.50, and 0.70, the conditions and multiplication factors would need updating: `if (calls <= 100) amount = calls * 0.30; else if (calls <= 200) amount = (100 * 0.30) + ((calls - 100) * 0.50); else amount = (100 * 0.30) + (100 * 0.50) + ((calls - 200) * 0.70);`.

For larger datasets, improvements include using data structures like arrays to store tier information, applying algorithms to manage computations in batches, or leveraging parallel processing to distribute calculations across processors, reducing execution time.

Monthly charges consist of a fixed amount of 250. For 350 calls, the charges are calculated as follows: the first 100 calls are charged at 0.50 each (0.50 * 100), the next 100 calls at 0.60 each (0.60 * 100), and the remaining 150 calls at 0.75 each (0.75 * 150). Total variable charge = 50 + 60 + 112.5 = 222.5. Total charge = 250 + 222.5 = 472.5.

To modularize, encapsulate the conversion logic in a method like `public static double convertFahrenheitToCelsius(double fahrenheit)`, which can be called anywhere in the program. This promotes reusability and maintainability by isolating the conversion functionality from the main method.

Challenges include handling currency conversion rates, formatting numbers and dates per locale, translating messages, ensuring differing legal and tax considerations, and adapting to different telecommunications standards and billing practices across countries.

The fixed amount in the total bill provides a base charge that all customers pay regardless of use, which decreases the relative variability of the total bill compared to variable charges only. This means low users pay relatively more per call due to the fixed cost.

The current conditional logic is straightforward but not optimal for scalability. A more efficient approach could be using a loop or data structure to handle different tiers, reducing duplication and potential errors in case of changes. It can also improve maintainability by avoiding hard-coded values.

The conversion formula from Fahrenheit to Celsius used in the code is: Celsius = (Fahrenheit - 32) * 5 / 9. To convert 212°F to Celsius: Celsius = (212 - 32) * 5/9 = 100°C.

You might also like