Question
Hello expert; Question: The Fast Freight Shipping Company charges the following rate: Weight of Package Shipping Rate Per 500 miles 2 pounds or less $1.10
Hello expert;
Question:
The Fast Freight Shipping Company charges the following rate:
Weight of Package | Shipping Rate Per 500 miles |
2 pounds or less | $1.10 |
Over 2 pound but no more than 6 pounds | $2.20 |
Over 6 pound but no more than 10 pounds | $3.70 |
Over 10 Pounds | $4.80 |
The shipping rate per 500 miles are not prorated. For example, if a 2-pound package is shipped 550 miles, the shipping charges will be $2.20. If a 6.5-pound package is shipped 1150 miles, the shipping charges will be $11.10. Write a program that asks for user to enter the weight of a package, and the number of miles shipped. The program will then calculate and display the shipping charges for the package.
can you check my java code please?
Thank you
1 //import the packages 2 import java.swing.JOptionPane; 3 4 //class shippingCharges 5 class shippingCharges 6 { 7 //main method 8 public static void main(String[]args) 9 { 10 //declare varible 11 double charge= 0.0; 12 int dist=0; 13 String input; 14 //Promt and read the weight of a package from the user 15 input= JOptionPane.shouwInputDialog("Enter the weight of the package"); 16 double weight= Math.ceil(Double.parseDouble(input)); 17 //Promt and read the number of miles shipped from the user 18 input= JOptionPane.showInputDialog("Enter the number of miles shipped"); 19 int miles= Integer.parseInt(input); 20 //The weight of a package is 2 pounds or less 21 if (weight <=2) 22 { 23 while (miles !=0); 24 { 25 miles= miles/500; 26 dist = dist + 1; 27 } 28 charges = 1.10 * dist; 29 } 30 //The weight of Package is over 2 pounds but not more than 6 pounds 31 else if (weight <=6) 32 { 33 while (miles>0) 34 { 35 miles = miles -500; 36 dist= dist + 1; 37 } 38 charges = 2.20 * dist; 39 40 //The weight of Package is 6 pounds but not more than 10 pounds 41 else if (weight <=10) 42 { 43 while (miles>0) 44 { 45 miles = miles -500; 46 dist= dist + 1; 47 } 48 charges = 3.70 * dist; 49 } 50 //The weight of Package is over 10 pounds 51 else 52 { 53 while (miles>0) 54 { 55 miles = miles -500; 56 dist= dist + 1; 57 } 58 charges = 3.80 * dist; 59 } 60 //Display the shipping charges 61 JOptionPane.showMessageDialog(null,"The shipping charges for the packages is $:" + charges); 62 } 63 64 65
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started