KnowledgeBoat Logo

Computer Applications

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

WeightCharges
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.

Java

Java Conditional Stmts

112 Likes

Answer

import java.util.Scanner;

public class KboatMayurTpt
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter parcel weight: ");
        double wt = in.nextDouble();
        double amt = 0;
        
        if (wt <= 10)
            amt = 30 * wt;
        else if (wt <= 30)
            amt = 300 + ((wt - 10) * 20);
        else
            amt = 300 + 400 + ((wt - 30) * 15);
            
        System.out.println("Parcel Charge = " + amt);
    }
}

Output

BlueJ output of Mayur Transport Company charges for parcels as per the following tariff: Write a program in Java to calculate the charge for a parcel, taking the weight of the parcel as an input.

Answered By

48 Likes


Related Questions