programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Java assignment for class - stumped

Greenhorn
Posts: 2
I know there are a lot of boolean and if/else statements involved, but I have no idea where to start with this. Can someone help me get off the ground?

Write the Java source code necessary to build a solution for the following problem:
Changes in the economy have determined that for the EZ shipping company, a surcharge will be assessed on all packages that meet certain criteria. The surcharge is a function of the characteristics of the package and the zip code to which it is sent.

If the first digit of the zip code is a "4," then there is an additional surcharge of 5% on the shipping cost. If the first digit of the zip code is a "6," then there is an additional shipping cost surcharge of 9% of the shipping cost. For all other zip codes there is an additional shipping cost surcharge of 14% of the shipping cost. Additionally, if the zip code is even, then there is an additional charge of 2% of the shipping cost.

Tip: if it's not said then do it! The assignment doesn't require users to input all five numbers on a zipcode. You can just ask your user to input the first number of their zipcode.

In addition to the surcharges, the regular charges for shipping are calculated as follows:

For all weights under five pounds, the charge is \$12.00.

For weights over five pounds, the charge is calculated as follows:

If length * width * height is:
a. Between 5.1 and 15, the charge is 14.00
b. Between 15. 1 and 34, the charge is 17.00
c. Between 34. 1 and 45, the charge is 21.00
d. Between 45.1 and 60, the charge is 33.00
e. Greater than 60, the charge is 105.00
Write a program that allows the user to input the zip code and the characteristics of the package then prints out the following:
The zip code and dimensions of the package
The shipping cost
The surcharge
The total shipping cost (shipping cost plus surcharge)

Sheriff
Posts: 4756
133
Welcome to the Ranch!

It sometimes helps if you start by writing an outline of what you are going to do, breaking each task into smaller tasks. At that point, it may be easier to see how to turn them into Java code.

Try that, and post your program (please UseCodeTags) and we'll see if we can guide you further.

Marshal
Posts: 5593
384
Jenni Reuter,

Did you come up with something? Post it what you got, so the guys could give you some advices.

Jenni Reuter
Greenhorn
Posts: 2
Hey, guys. Here's what I came up with along with a tutoring lesson from my teacher.
Please let me know if there's any way to polish it up or make it better.

Knute Snortum
Sheriff
Posts: 4756
133
Good job! I noticed that you have small "holes" in your if statements, for instance, what if the dimension is 15.05? Can you figure out a way to stop those holes?

Liutauras Vilda
Marshal
Posts: 5593
384
• 1
Great Jenni.
Beside Knute's mentioned points, you could name variables as Java convention says: start variable names with lower case and the second word start with upper case.

So you could change to additionalCharge and totalCost. In general it improves your code readability and it is a good practise, you'll notice profit later during your practice.

 Consider Paul's rocket mass heater.