0% found this document useful (0 votes)
14 views2 pages

Telegram and Water Bill Calculators

The document contains code for 3 programs that calculate charges or wages based on input values and rates. The first program calculates telegram charges based on number of words entered. It charges Rs. 15 for the first 15 words and additional rates for words after 15. The second program calculates water bill based on number of gallons entered. It applies different rates per gallon depending on the quantity of gallons within set thresholds. The third program calculates wages based on hours worked and hourly rate. It pays regular rate for first 35 hours, 1.5 times rate for next 25 hours, and 2 times rate for next 20 hours, with a maximum of 80 hours per week.

Uploaded by

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

Telegram and Water Bill Calculators

The document contains code for 3 programs that calculate charges or wages based on input values and rates. The first program calculates telegram charges based on number of words entered. It charges Rs. 15 for the first 15 words and additional rates for words after 15. The second program calculates water bill based on number of gallons entered. It applies different rates per gallon depending on the quantity of gallons within set thresholds. The third program calculates wages based on hours worked and hourly rate. It pays regular rate for first 35 hours, 1.5 times rate for next 25 hours, and 2 times rate for next 20 hours, with a maximum of 80 hours per week.

Uploaded by

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

1 Prepared by:- Raj Kumar Jain

Query from Tiya


Q.4 Write a program to input number of words. Calculate and print telegram charges according to the
following condition.
No of words Charge
Fist 15 words Rs. 15
Next 10 words Additional Rs. 1.50 per word
Above 25 words Additional Rs. 1 per word

import [Link].*;
class bill
{
public static void main ( )
{
Scanner sc = new Scanner ([Link]);
int nw;
double ch;
[Link] ( “Enter No of Words “);
nw=[Link]( );
if (nw<=15) …………………………………………… 1
ch=15;
else if (nw>15 && nw<=25) …………………………………………… 2
ch=15 + ((nw-15)*1.50);
else …………………………………………… 3
ch=15 + (10*1.50) + ((nw-25)*1);
[Link](“charge = “+ch);
}
}

Query from Dhairya Bansal Q.5 and Q.6


Q.5 Write a program to input number of gallons. Calculate and print total water bill according to the
following condition.
No of Gallons Rate per gallons
First 1000 gallons 0.25 per gallons
Next 2500 gallons 0.50 per gallons
Next 5000 gallons 0.75 per gallons
Above 8500 gallons 0.90 per gallons

import [Link].*;
class bill
{
public static void main ( )
{
Scanner sc = new Scanner ([Link]);
int ng;
double ch;
1 Prepared by:- Raj Kumar Jain
[Link] ( “Enter No of Gallons “);
ng=[Link]( );
if (ng<=1000) …………………………………………… 1
ch=ng*0.25;
else if (ng>1000 && ng<=3500) …………………………………………… 2
ch=(1000*0.25) + ((ng-1000)*0.50);
else if (ng>3500 && ng<=8500) …………………………………………… 3
ch=(1000*0.25) + (2500*0.50) + ((ng-3500)*0.75);
else …………………………………………… 4
ch=(1000*0.25) + (2500*0.50) + (5000*0.75)+((ng-8500)*0.90);
[Link](“charge = “+ch);
}
}

Q.6 A man is paid the hourly rate for the first 35 hours he works in a week. Thereafter he is paid 1.5 times
the hourly rate for the next 25 hours he works in a week and at twice the hourly rate for the next 20 hours
in a week. He is not allowed the work for more the 80 hours in a week. Write a program to input number
of hours and hour rate calculate and print wages.

import [Link].*;
class wages
{
public static void main ( )
{
Scanner sc = new Scanner ([Link]);
int nh, hr;
double wa;
[Link] ( “Enter No of Hours and Hour Rate “);
nh=[Link]( );
hr=[Link]( );
if (nh<=35) …………………………………………… 1
wa=nh*hr;
else if (nh>35 && nh<=60) …………………………………………… 2
wa=(35*hr) + ((nh-35)*(hr*1.5));
else if (nh>60 && nh<=80) …………………………………………… 3
wa=(35*hr) + (25*(hr*1.50) + (nh-60)*(hr*2));
[Link](“Wages = “+wa);
}
}

Common questions

Powered by AI

The water bill pricing structure embraces marginal cost pricing to promote responsible consumption and discourage waste. By charging progressively higher rates for increased consumption—as seen from 0.25 per gallon initially, then increasing to 0.90 per gallon for those using above 8500 gallons—the structure incentivizes conservation. This approach aligns with economic principles wherein prices are used to regulate demand, ensuring that higher consumption levels are discouraged by higher costs, thus reflecting supply limitations and supporting sustainability .

The coding pattern efficiently utilizes conditional statements to apply different billing rates based on tiers of water usage. By segmenting the calculation into if-else statements, the program correctly computes costs for each tier: the first 1000 gallons at 0.25 per gallon, the next 2500 gallons at 0.50, the subsequent 5000 gallons at 0.75, and any usage above 8500 gallons at 0.90. This modular approach enhances readability and maintenance. The design allows precise and flexible application of charges, resembling a real-world progressive tax structure for resource usage .

If a person works precisely 60 hours, the calculation falls under the condition where hours worked are greater than 35 but less than or equal to 60. In this case, the wages are calculated as the sum of the regular pay for the first 35 hours and 1.5 times the hourly rate for the next 25 hours. Mathematically, it can be expressed as: wages = (35 * hr) + ((60 - 35) * (hr * 1.5)). This formula ensures the appropriate overtime rate is applied for hours worked beyond the initial 35 .

Adapting the water bill calculation program to various regional pricing models could introduce several challenges. Different regions might have unique structures such as fixed fees irrespective of usage, subsidies for certain gallon thresholds, or even tier-based discounts. Implementing these changes would require substantial restructuring of existing logic. An even greater challenge could be designing the program to be flexible and configurable enough to handle diverse pricing models dynamically without hardcoded changes, potentially involving configuration files or databases to store different regional rules and logic to dynamically parse and apply these rules efficiently .

Progressive pricing, as implemented in the telegram and water bill programs, incentivizes efficiency and conservation. This model can be applied effectively in other utilities, such as electricity, gas, or internet services. By charging higher rates for higher tiers of usage, companies discourage wasteful consumption and promote sustainable practices. In electricity billing, for example, progressive pricing ensures lower consumption is cheaper, whereas excess usage incurs progressively higher costs, mirroring supply constraints and encouraging energy efficiency. Such systems also enable utility providers to better manage demand, stabilize supply, and encourage users to be more conscious of their consumption habits .

The telegram billing logic employs a tiered structure that is already conducive to scalability. Introducing additional word usage tiers would necessitate extending the logic by adding further conditions in the if-else structure. While the simplicity of the current methodology aids understanding, adding many tiers could increase complexity, potentially reducing readability and maintainability without restructuring the code architecture, such as using arrays or maps to hold tier data dynamically. Exploration of patterns like polymorphism or external configuration files could address scalability for large-scale applications .

The program does not include specific handling or validation for negative input values, which could lead to logical errors or nonsensical results. If negative hours are input, the conditions set in the if-else structure do not account for this invalid data, leading to incorrect calculations for wages, such as outputting a negative salary. This highlights the importance of input validation to avoid and mitigate such anomalies in user-provided data .

To modify the hourly wage calculation program to accept only valid input values, one could implement input validation logic. This involves checking if the number of hours worked (nh) and the hourly rate (hr) are non-negative and within reasonable bounds before processing. This can be done using an additional conditional statement at the start of the program, such as: ‘if (nh < 0 || hr < 0) { System.out.println("Invalid input."); return; }’. This ensures the program only proceeds with valid, logical data, preventing errors and inappropriate calculations due to erroneous input .

To incorporate an additional tax percentage on the final telegram charge, the program could include a calculation step after determining the basic charge. For instance, applying a tax rate of T% would involve adding an expression like ‘ch += ch * (T/100);’ after calculating the original charge ‘ch’ based on word count. This would succinctly adjust the total to account for taxation, demonstrating how charges can be adjusted dynamically based on varying economic conditions or policy requirements .

For words beyond the first 25 in a telegram, the charge is calculated by adding Rs. 1 per word to the base charge. After calculating the charge of Rs. 15 for the initial 15 words, plus the additional charges of Rs. 1.50 per word for the next 10 words, the formula for words beyond 25 is: charge = 15 + (10 * 1.50) + ((nw - 25) * 1). This incremental charging represents a tiered pricing strategy to reflect the marginal costs associated with longer messages .

You might also like