Question

In: Computer Science

5) Create the following in a Java program Create a scanner Prompt the user to enter...

5) Create the following in a Java program


Create a scanner
Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner
Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner
Prompt the user to enter the weight of the package and create variable to relate to scanner
Calculate cost of shipping
If the weight of box of mail is above 50 the box cannot not be shipped
inside of else create double variable where is called cost of pound
then you do more condition where if weight is between o and 1 cost of pound is 3.5
then if weight is less equal to 3 cost of pound is 5.5
then if weight is less equal to 10 cost of pound is 8.5
everything else cost of pound is 10.5
Display inside of condition shipping cost by multiplying cost of pound with weight

Solutions

Expert Solution

In case of any query do comment. Please rate answer as well. Thanks

Code:

import java.util.*;

public class ShippingCostCalculator
{
        public static void main(String[] args) {
                Scanner scnr = new Scanner(System.in);
      //read from where shipping is happening
                System.out.print("Enter the name where the box of mail is shipping from: ");
                String from = scnr.nextLine();
                
      //read where shipping is going
                System.out.print("Enter the name of destination where the box of mail will be shipped: ");
                String to = scnr.nextLine();
                
      //read the weight of the package
                System.out.print("Enter the weight of the package: ");
                int weight = scnr.nextInt();
                
                if (weight > 50) 
                    System.out.println("Box can not be shipped"); //if weight is above 50, can't ship
                else{
         
                    double costOfPound =0.0;
          //now calculate the cost of pound
                    if(weight ==0 || weight == 1)
                        costOfPound = 3.5;
                    else if(weight <= 3)
                        costOfPound = 5.5;
                    else if(weight <= 10)
                        costOfPound = 8.5;
                    else
                        costOfPound = 10.5;
                    //print the shipping cost
                    System.out.printf("Shipping Cost: $%.2f\n", costOfPound * weight);
                        
                }
                
        }
}

==============screen shot of the code=========

output:


Related Solutions

Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
6) Create the following in a Java Program: Create payroll system Prompt the user to enter...
6) Create the following in a Java Program: Create payroll system Prompt the user to enter payroll information Employee name and create variable for scanner Hours worked Hourly pay rate Federal tax rate State tax rate Declare variable doubles for gross pay, federal, state and total deduction Display payroll statement example: Name of employee Hours worked Hourly pay rate Gross pay which is equal hours worked multiply hourly pay rate Federal withholding which is equal of gross pay multiply federal...
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
Create a Java program that asks a user to enter two file names. The program will...
Create a Java program that asks a user to enter two file names. The program will read in two files and do a matrix multiplication. Check to make sure the files exist. first input is the name of the first file and it has 2 (length) 4 5 6 7 Second input is the name of the second file and it has 2 (length) 6 7 8 9 try catch method
Create in java an interactive GUI application program that will prompt the user to use one...
Create in java an interactive GUI application program that will prompt the user to use one of three calculators, label project name MEDCALC. You can use any color you want for your background other than grey. Be sure to label main java box with “MEDCALC” and include text of “For use only by students” On all three calculators create an alert and signature area for each user. The alert should be something like “All calculations must be confirmed by user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
IN C This assignment is to write a program that will prompt the user to enter...
IN C This assignment is to write a program that will prompt the user to enter a character, e.g., a percent sign (%), and then the number of percent signs (%) they want on a line. Your program should first read a character from the keyboard, excluding whitespaces; and then print a message indicating that the number must be in the range 1 to 79 (including both ends) if the user enters a number outside of that range. Your program...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once...
JAVA Programming Implement the class DataProcess and prompt a user to enter 5 integer numbers. Once The program should output the average, largest, and smallest of 5 numbers. You must implement the methods listed below in your program. static float getAverage(int[] data) {...} static int getLargest(int[] data) {...} static int getSmallest(int[] data) {...}
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT