Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Conditional Constructs in Java

Chapter 8

Conditional Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Calculate the Parcel Charge based on the Weight Slabs


28. Mayur Transport Company charges for parcels as per the following tariff:

Weight

Charges

Upto 10 Kg.

Rs. 30 per Kg.

For the next 20 Kg.

Rs. 20 per Kg.

Above 30 Kg.

Rs. 15 per Kg.

Write a program in Java to calculate the charge for a parcel, taking the weight of the parcel as an input.

import java.util.Scanner;

 

public class ParcelCharge {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        int weight;

        double charge = 0;

 

        System.out.print("Enter the weight of the parcel (in Kg): ");

        weight = sc.nextInt();

 

        if (weight <= 10) {

            charge = weight * 30;

        } else if (weight <= 30) {

            charge = (10 * 30) + ((weight - 10) * 20);

        } else {

            charge = (10 * 30) + (20 * 20) + ((weight - 30) * 15);

        }

 

        System.out.println("Total Parcel Charge = Rs. " + charge);

    }

}

Output

Sample Run 
Enter the weight of the parcel (in Kg): 35
Total Parcel Charge = Rs. 775.0

Calculation

  • First 10 kg → 10 × 30 = 300
  • Next 20 kg → 20 × 20 = 400
  • Remaining 5 kg → 5 × 15 = 75
  • Total = Rs. 775

Explanation

  • The program takes the parcel weight as input using Scanner.
  • It uses an if–else ladder to apply slab-wise charges:
    • First slab charged fully before moving to the next.
  • The final charge is displayed in rupees.