Shipping Cost

Lab Java Intermediate 20 points

Read a parcel weight (kg, decimal) and a zone (local, national, international). Base cost: up to 1 kg 50, up to 5 kg 120, more 250. National multiplies by 1.5, international by 3. Orders over 1000 after the multiplier get 10% off. Print the cost with 2 decimals, or unknown zone.

Input

One line: weight zone.

Output

One line.

Example

Input

0.5 local

Output

50.00
Sample input available Sample output available
Editor
Java

Hints

Work out the base cost, then apply the zone, then the discount.

return inside main ends the program.

Solution explanation

Breaking a pricing rule into stages keeps every condition simple.

Show solution
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double weight = sc.nextDouble();
        String zone = sc.next();
        double cost = weight <= 1 ? 50 : weight <= 5 ? 120 : 250;
        if (zone.equals("national")) {
            cost *= 1.5;
        } else if (zone.equals("international")) {
            cost *= 3;
        } else if (!zone.equals("local")) {
            System.out.println("unknown zone");
            return;
        }
        if (cost > 1000) {
            cost *= 0.9;
        }
        System.out.printf("%.2f%n", cost);
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD