Problem 2: (30 points) In this lab you will create an application that computes
ID: 3639515 • Letter: P
Question
Problem 2: (30 points)In this lab you will create an application that computes charges to ship a package.
Create a new project, in the project will be two classes: ShippingCharges and ShippingChgDriver.
Class ShippingCharges
Attributes: weight, distance, charge
Create the getters and setters for all attributes
Create one constructor that will take as input the weight and distance of the package.
Create one method that will calculate the shipping charges.
Create one method to print the shipping charge.
Class ShippingChgDriver
Prompt user to enter the weight and distance
Create one object of type ShippingCharges
Run calculate shipping charges method.
Run the print shipping charge.
Note: Use message display boxes for both input and output messages.
Run the program on the test cases listed below.
Shipping Charges if logic.
Weight of Package (Kg) Rate Per 500 Miles Shipped
2 kg or less $1.10
Over 2 kg but not more than 6 kg $2.20
Over 6 kg but not more than 10 kg $3.70
Over 10 kg $4.80
The shipping charges per 500 miles are not prorated. For example, if a 2 kg package is shipped 550 miles, the charges would be $2.20.
Explanation / Answer
I can't help but notice that public double charge(double weight, double distance) doesn't always return a value, yet it should. Also you can always nest if statements or use if else statements if creating a large condition isn't panning out the way you expected, as well as using additional brackets to make it clear to the computer what your trying to evaluate. I might change the charge function to something like the following: public double charge(double weight, double distance) { if((weight0) || (distance0)) { charge = 1.10; } else return charge; } Unless your second if statement should assign a different value to charge, in which case I'd use: if((weight0) || (distance0)) { charge = 1.10; } else if((weight>2 && weight 500) { charge = somevalue; } return charge; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.