In Java Assign shipCostCents with the cost of shipping a pac

In Java Assign shipCostCents with the cost of shipping a package weighing shipWeightPounds. The cost to ship a package is a flat fee of 75 cents plus 25 cents per pound. Declare and use a final int named CENTS_PER_POUND.

Solution

// ShippingCost.java

import java.util.Scanner;

public class ShippingCost
{
   public static void main(String args[])
   {
       double shipWeightPounds;
       double shipCostCents;
       final int FLAT_FEE_CENTS = 75;
       final int CENTS_PER_POUND = 25;
      
       Scanner sc=new Scanner(System.in);
        System.out.print(\"Enter package weight(lb): \");
        shipWeightPounds = sc.nextDouble();

       shipCostCents = FLAT_FEE_CENTS + CENTS_PER_POUND*shipWeightPounds;

       System.out.println(\"\ Weight(lb): \"+ shipWeightPounds);
       System.out.println(\"Flat fee(cents): \"+ FLAT_FEE_CENTS);
       System.out.println(\"Cents per lb: \"+ CENTS_PER_POUND);
       System.out.println(\"Shipping cost(cents): \"+ shipCostCents + \" cents\");
   }
}

/*
output:

Enter package weight(lb): 10

Weight(lb): 10.0
Flat fee(cents): 75
Cents per lb: 25
Shipping cost(cents): 325.0 cents

*/

In Java Assign shipCostCents with the cost of shipping a package weighing shipWeightPounds. The cost to ship a package is a flat fee of 75 cents plus 25 cents p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site