Advertisement
Spocoman

Courier Express

Sep 4th, 2024 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         double weight = Double.parseDouble(scanner.nextLine());
  7.         String service = scanner.nextLine();
  8.         int distance = Integer.parseInt(scanner.nextLine());
  9.         double standardPrice = 0, expressPrice = 0;
  10.  
  11.         if (weight < 1) {
  12.             standardPrice = 0.03;
  13.         } else if (weight >= 1 && weight < 10) {
  14.             standardPrice = 0.05;
  15.         } else if (weight >= 10 && weight < 40) {
  16.             standardPrice = 0.10;
  17.         } else if (weight >= 40 && weight < 90) {
  18.             standardPrice = 0.15;
  19.         } else if (weight >= 90 && weight < 150) {
  20.             standardPrice = 0.20;
  21.         }
  22.  
  23.         if (service.equals("express")) {
  24.             if (weight < 1) {
  25.                 expressPrice = standardPrice * 0.80;
  26.             } else if (weight >= 1 && weight < 10) {
  27.                 expressPrice = standardPrice * 0.40;
  28.             } else if (weight >= 10 && weight < 40) {
  29.                 expressPrice = standardPrice * 0.05;
  30.             } else if (weight >= 40 && weight < 90) {
  31.                 expressPrice = standardPrice * 0.02;
  32.             } else if (weight >= 90 && weight < 150) {
  33.                 expressPrice = standardPrice * 0.01;
  34.             }
  35.         }
  36.  
  37.         double totalPrice = standardPrice * distance + expressPrice * distance * weight;
  38.         System.out.printf("The delivery of your shipment with weight of %.3f kg. would cost %.2f lv.\n", weight, totalPrice);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement