Java languageThe cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.1. Declare a constant named CENTS_PER_POUND and initialize with 25.2. Get the shipping weight from user input storing the weight into shipWeightPounds.3. Using FLAT_FEE_CENTS and CENTS_PER_POUND constants, assign shipCostCents with the cost of shipping a package weighing shipWeightPounds.import java.util.Scanner;public class ShippingCalculator { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int shipWeightPounds; int shipCostCents = 0; final int FLAT_FEE_CENTS = 75;int CENTS_PER_POUND = 25;shipWeightPounds=10;shipCostCents = (shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS; System.out.println("Weight(lb): " + shipWeightPounds); System.out.println("Flat fee(cents): " + FLAT_FEE_CENTS); System.out.println("Cents per pound: " + CENTS_PER_POUND); System.out.println("Shipping cost(cents): " + shipCostCents); }}

Respuesta :

Answer:

// Here is code in Java.

// import package

import java.util.*;

// class definition

class Main

{

   // main method of the class

public static void main (String[] args) throws java.lang.Exception

{

    try{

   // variables

    final int CENTS_PER_POUND = 25;

    final int FLAT_FEE_CENTS = 75;

    // Scanner object to read input

   Scanner sr=new Scanner(System.in);

   System.out.print("Enter the shipping weight:");

   // read the input weight

   int shipWeightPounds=sr.nextInt();

   // calculate total cost

  int shipCostCents = (shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS;

  // print Weight

  System.out.println("shipping  Weight: " + shipWeightPounds);

  // print flat fee

     System.out.println("flat fee of shipping in cents : " + FLAT_FEE_CENTS);

     // print cents per round

     System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND);

     // print cost of Shipping

    System.out.println("total cost of shipping in cents: " + shipCostCents);

   

   

   }catch(Exception ex){

       return;}

}

}

Explanation:

Declare and initialize two constant variables "CENTS_PER_POUND=25" & "FLAT_FEE_CENTS = 75". Read the input weight from user with the help of Scanner class object. Then  calculate the cost of shipping by multiply weight with cent per pound and add flat fee. Then print each of them.

Output:

Enter the shipping weight:12                                                                                                                                  

shipping  Weight : 12                                                                                                                                        

flat fee of shipping in cents: 75                                                                                                                              

Cents/pound for shipping: 25                                                                                                                                  

total cost of shipping in cents: 375  

Answer:

final int CENTS_PER_POUND = 25;

     shipWeightPounds=scnr.nextInt();

     shipCostCents = ((shipWeightPounds * CENTS_PER_POUND) + FLAT_FEE_CENTS);

Explanation:

Ver imagen DarthVaderBarbie