ICSE Class 10 Computer Applications
Question 28 of 43
Conditional Constructs in Java — Question 28
Back to all questions 28
Question Question 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 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
