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 9

Conditional Constructs in Java

Class 9 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Programs - Parcel Charge Calculation (Slab System)


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 ParcelChargeCalculator {

    public static void main(String[] args) {

 

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter parcel weight (in kg): ");

        double weight = sc.nextDouble();

 

        double charge = 0;

 

        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("\nTotal Parcel Charge = Rs. " + charge);

 

        sc.close();

    }

}

Output

Output 1 :

SAMPLE INPUT : Enter parcel weight (in kg): 8 SAMPLE OUTPUT : Total Parcel Charge = Rs. 240.0

Output 2 :

SAMPLE INPUT : Enter parcel weight (in kg): 25 SAMPLE OUTPUT : Total Parcel Charge = Rs. 700.0

Output 3 :

SAMPLE INPUT : Enter parcel weight (in kg): 40 SAMPLE OUTPUT : Total Parcel Charge = Rs. 1150.0

Explanation

1. Input

  • The user enters the parcel weight in kilograms.

2. Slab-wise Calculation

  • Up to 10 kg

                        Charge = Weight × 30

  • 11 to 30 kg

                        Charge = (10 × 30) + (Remaining × 20)

  • Above 30 kg

                        Charge = (10 × 30) + (20 × 20) + (Remaining × 15)

3. Output

  • Displays the total parcel charge.