CPSC 120A -- Assignment #1:Humanitarian Aid Shipments
Due Friday, September 19, 2008 by 4 p.m.
The news of hurricanes in the last several weeks has made it clear that
disaster planning and relief is both important and difficult.
For this assignment you will write a Java program to help a
relief organization plan the shipment of supplies to
a disaster area.
The relief agency ships supplies to a disaster area in tractor
trailers that measure 53 feet long, 98 inches wide, and 124 inches
high on the interior. The agency needs a program that will help them
compute the number of boxes of supplies they can afford to send and
the number of trucks needed to send the
supplies to the disaster area. They also would like additional information
calculated such as the cost of the shipment and
the time it would take the trucks to reach
the disaster area. These
values of course depend on things such as what commodity they are
shipping, how much money they have available to buy the
commodity, and
the distance to the disaster area. It is assumed that all items are
shipped in rectangular boxes and all boxes in a given shipment
are the same size.
The program must meet the following requirements:
Input to the program will be:
- the dimensions (width, length, height) of a box (in inches)
- the cost of one box
- the total amount of money available for buying the commodity
- the distance to the disaster site (in miles)
Values to compute:
- The number of boxes the agency can afford to purchase
- The number of boxes that will fit in each truck
- The total number of trucks needed to ship the supplies (assuming
only full trucks are sent - see the assumptions below)
- The number of boxes the agency will actually send (since the
agency will only send full trucks they may actually send fewer
boxes than they can afford to buy)
- The total cost of purchasing the supplies
- The amount of time (in days and hours) it will take the
shipment to arrive at the disaster site.
Assumptions: Your calculations should be based on the
following assumptions and requirements.
- The boxes must be loaded upright in the truck; however, there
would be two possible orientations. For example, if the boxes are
48 inches long by 36 inches wide by 54 inches high they can be
put in the truck either with the 48 inch side going the length of
the truck or with the 36 inch side going the length of the truck.
Your program should compute the number of boxes that fit in each
direction and then select the maximum (there is a method in the
Math class to do this).
- Assume the agency will only send trucks that are filled to capacity.
So for example, if they can afford 425 boxes and each truck can
hold 100 boxes they will only buy 400 boxes and send 4 full trucks.
- To compute the time it takes, assume the average speed over
the whole trip is 50 miles per hour. Assume that each truck will
have two drivers so they can drive constantly (federal regulations
require that a driver can drive no more than 10 hours without
an 8 hour rest but in this case one driver can rest while the
other drives).
The average speed takes into account short breaks. Hence if the
distance to the disaster site is 1,430 miles the estimate of driving time is
28 hours (it is actually 28.6 but we will use the whole part as
an estimate for our calculations) which is 1 day and 4 hours.
Output Your output must
be nicely formatted (similar to that below but you should choose
your own way of formatting) and must include the following information (all
appropriately labeled with white space):
- The size of a box (in inches) -- this is a repeat of the input
- The total number of boxes that will fit in a truck
- The maximum number of boxes that can be purchased with the
available funds
- The number of trucks needed
- The number of boxes that will be shipped
- The total cost of the boxes that are shipped
- How long (expressed as days and hours) it would take the
trucks to make the trip. Note: Any fractional hour be should truncated
(dropped down to the next whole hour - see the assumptions above).
Sample Output (NOTE: This shows the prompts and input of
36 48 54 for the dimensions
of the box; $24,000 for the amount of money available for
purchasing the commodity being shipped;
$55 for the cost per box and 1430 for the distance. The input
by the user is in bold.)
Analysis of Shipment of Humanitarian Supplies
=============================================
Enter size of each box to be shipped ---
width, length, height (in inches): 36 48 54
Enter the amount of money available $: 24000
Enter the cost per box: 55
Enter the distance to the disaster site: 1430
Shipment Summary
****************
Box size (in inches): 36 by 48 by 54
Number of Boxes that will fit in a truck: _____
Maximum number of boxes that can be purchased: ____
Number of Trucks Needed: _____
Number of boxes to be shipped: _______
Total cost of the shipment: $ ______
Time to reach the disaster area: ____ days and ____ hours
Additional Requirements:
- Your program must be in a package named assign1. You
should create a subdirectory of your Assignments directory named
assign1 (just as you create subdirectories of Labs for each lab).
In Eclipse, highlight the Assignments project in the workbench,
open the File menu, expand the new option, and
select package. Name the package assign1.
- You must use meaningful names for variables, constants, and
your class. Use Java conventions for case -- constants (declared
with final) are all uppercase (with the underscore separating words),
variables start with a lowercase letter (but each separate word
within the variable starts with a capital), the class name is
capitalized.
Choosing meaningful names makes your program easier to read and follow.
- You must use constant identifiers where appropriate (there are
several constants in the program).
- Use appropriate data types - for example, you can't have part of a
truck so the number of trucks should be stored in an int variable!
- Use white space (blank lines and blank spaces) in your program to make
it easier to read. Separate the sections of the program with blank lines.
Indent and align your code properly (Eclipse helps you do this -
it automatically
indents in most cases and will properly format your program
if you use CRTL-SHIFT F or use the menu.)
- Your program must compile!!! A program with a compilation
error, no matter how small, will receive at most 25% credit. Your
program must compile and run.
- Document your program. At the top you must have documentation that
includes a brief description of
what the program does (this should include a list of the input expected
and the output the program will produce), the date, and your name.
Similarly you should have documentation before the main method and
some in-line documentation (use the // style of comments) indicating
each major section of code.
- Hand In: A printed copy of your program (the source code).
- E-mail: Your source code
to your instructor (ingram@roanoke.edu or bouchard@roanoke.edu).
Academic Integrity Reminder!!! Programming
assignments are to be your own work. You may get help on the specifics
of the assignment from no one except the instructor. You may not show
your program to anyone or look at anyone else's program or share ideas
with anyone about how to write the program or solve the problem.
Suggestions for completing the assignment
- Read the whole assignment description before starting!!!
- Perform the calculations by hand so you understand what needs
to be done. For example, figure out how many boxes can fit in the truck
for a concrete example. Note that this takes a few steps so you (and
later your program) will need to do several intermediate
calculations. For the example box size of 48 inches long by
36 inches wide, by 54 inches high figure out each of the following:
- how many boxes can be stacked on top of each other
(remember the boxes must be loaded upright in the truck)?
- how many can fit if the boxes are put in the truck with the 48 inch
side going the length of the truck?
- how many can fit if the boxes are put in the truck with the 36 inch
side going the length of the truck?
- what is the maximum number that can fit in the truck?
- Implement the program incrementally (remember "implement" is
actually writing the code). That is, do part of the code and make
sure that part is right before adding more. What would be
a good place to start? What are some ways you could break the
task up into smaller steps?
- Test, Test, Test!!! Make sure your program is correct
for a variety of input!