Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help to write the Java programe The Fast Freight Shipping Company charges

ID: 3674988 • Letter: I

Question

I need help to write the Java programe

The Fast Freight Shipping Company charges following rates Write a Java program that asks for the weight of the package and the distance to be shipped, and then display charges Input validation: Do not accept 0 or less for the weight of the package. If the weight of the package is O or less, display the message "weight should be a greater than 0" Do not accept more than 20 for the weight of the package. If the weight of the package is 20 or more, display the message "max weight should 20 " Also, do not accept the distances of less than 10 and greater than 3000

Explanation / Answer

ShippingCharges.java

package org.students;

import java.util.Scanner;
import java.text.DecimalFormat;

public class ShippingCharges {
   public static void main(String[] args) {
       Scanner in = new Scanner(System.in);
       // To Print the Cost in Required Format we created DecimalFormat.
       DecimalFormat df = new DecimalFormat("#.00");
       double weight, distance, distanceTemp;
       double cost = 0.0;
       int count = 0;

       System.out
               .println(":: Welcome to The Fast Freight Shipping Company Rates are determined by Weight of Packages (in Kilograms) and Distance traveled (in Miles) Rates are charged per 500 miles Shipped ");
       // Untill the Customer Enters the correct range of Package weight the
       // program wont accept.
       while (true) {
           System.out.print("Enter Weight of Packages (in Kilograms): ");
           weight = in.nextDouble();
           if (weight <= 0) {
               System.out
                       .println(":: Weight should be greater than Zero(0) Kilograms ::");
               continue;
           } else if (weight > 20) {
               System.out.println(":: Max Weight should be 20 Kilograms ::");
           } else {
               break;
           }
       }

       // Untill the Customer Enters the correct range of courier distance the
       // program wont accept.
       while (true) {
           System.out.print("Enter Distance to be traveled (in Miles): ");
           distance = in.nextDouble();
           if (distance < 10) {
               System.out
                       .println(":: You Package does not meet the minimum travel distance requirement(Minimum distance is 10 miles) ::");
               continue;
           } else if (distance > 3000) {
               System.out
                       .println(":: You Package exceded the maximum travel distance requirement(maximum distance is 3000 miles) ::");
               continue;
           } else {
               break;
           }

       }

       distanceTemp = distance;

       while (distanceTemp > 0) {
           distanceTemp -= 500;
           count++;
       }

       if (weight <= 2) {
           cost = count * 1.10;
       } else if (weight > 2 && weight <= 6) {
           cost = count * 2.20;
       } else if (weight > 6 && weight <= 10) {
           cost = count * 3.70;
       } else if (weight > 10) {
           cost = count * 4.80;
       }

       System.out.println("The Cost of " + weight + " kg to travel "
               + distance + " miles is: $" + df.format(cost));
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote