Calculate the courier charges
Write a program to accept the weight of the parcel and calculate the bill according the given price slabs.
Write a program to accept the weight of the parcel and
calculate the bill according the given price slabs.
Weight Rates
per Kg
<=10Kg 30
Next 20 Kg 20
More than 30 kg 15
import java.io.*;
class charges
{
public static void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a weight");
double kg=Double.parseDouble(br.readLine());
double charge=0.0;
if(kg<=10)
{
charge=kg*30;
}
else if((kg>10)&&(kg<=30))
{
charge=10*30;
charge=charge+(kg-10)*20;
}
else
{
charge=10*30;
charge=charge+(20*20)+(kg-30)*15;
}
System.out.println("The amount to be paid is"+charge+"Rs");
}
}<tbody>
o/p Enter weight 5
The amount to be paid is150.0Rs
</tbody>
Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.