Advertisements
Advertisements
Question
A courier company charges differently for 'Ordinary' booking and 'Express' booking based on the weight of the parcel as per the tariff given below:
Weight of parcel | Ordinary booking | Express booking |
Up to 100 gm | ₹ 80 | ₹ 100 |
101 to 500 gm | ₹ 150 | ₹ 200 |
501 gm to 1000 gm | ₹ 210 | ₹ 250 |
More than 1000 gm | ₹ 250 | ₹ 300 |
Write a program to input weight of a parcel and type of booking ('O' for ordinary and 'E' for express). Calculate and print the charges accordingly.
Answer in Brief
Solution
import java.util.*;
public class Q8
{ public static void main(String args[])
{ Scanner in = new Scanner(System.in);
double wt, chrg = 0.0;
char ch;
System.out.printIn("Enter the weight of the parcel in grams");
wt = in.nextDouble();
System.out.printIn("Enter 'O' for ordinary and E' for express");
ch = in.next().toUpperCase().charAt(0);
switch(ch)
{
case 'O': if (wt <= 100)
chrg = 80;
else if (wt > 100 && wt <= 500}
chrg = 150;
else if (wt > 500 && wt <= 1000)
chrg = 210;
else if (wt > 1000)
chrg = 250;
System.out.printIn("Charge = " + chrg);
break;
case 'E': if (wt <= 100)
chrg = 100;
else if (wt > 100 && wt <= 500)
chrg = 200;
else if (wt > 500 && wt <= 1000)
chrg = 250;
else if (wt > 1000)
chrg = 300;
System.out.printIn("Charge = " + chrg);
break;
default: System.out.printIn("Invalid entry");
}}}
shaalaa.com
Is there an error in this question or solution?