CPSC 120 -- Assignment #1
Food Distribution
Due Friday, September 24, 2010 by 4 p.m.
Write a Java program to help a food bank distribution center plan
distribution of boxes of
donated food to the 15 local food pantries it serves.
When large quantities of food are donated to the food bank
the distribution center uses its
delivery truck, which is is 22.5 feet long, 7.75 feet wide, and
8.25 feet high, to deliver the food to the local food pantries.
Your program will help by computing quantities such as the number of
boxes that will fit in the truck, the number of local food pantries
that can be served with one truck load, and an estimate of the
time it will take to load the truck. A detailed list of
quantities to be computed, along with assumptions about how
the quantities are computed, is below.
Input to the program will be:
- the dimensions (length, width, height) of a box (in inches)
- the number of boxes donated
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):
- The dimensions and number of boxes (a repeat of the input)
- The total number of boxes that will fit in the truck
- The number of boxes each local food pantry will receive
- The number of left over boxes
- The number of local food pantries that one truck load can serve
- The number of trips needed to deliver to all food pantries
- The number of boxes in a "full" load
(see definition of "full" under the assumptions)
- The amount of space remaining in each "full" truck
(expressed in cubic feet)
- The estimated time, expressed as hours and minutes,
it takes to load a "full" truck
Assumptions: Your calculations should be based on the
following assumptions and requirements.
- The boxes are all the same size and
must be loaded upright in the truck. That is,
the value entered as the height of a box will determine how many
can be stacked up in the truck. However, there
would be two possible orientations. For example, if the boxes are
24 inches long by 20 inches wide by 14 inches high they can be
put in the truck either with the 24 inch side going the length of
the truck or with the 20 inch side going the length of the truck.
Your program should compute the number of boxes that fit both
directions and then select the maximum (use the max method in the
Math class to do this).
- Assume that each local food pantry gets the same number of
boxes and any left over stay at the distribution center. For example,
if 310 boxes are donated, each center gets 20 boxes with the 10
remaining staying at the distribution center.
- Further, assume that the number of boxes each local food pantry gets is
less than or equal to the number that will fit in the truck. That is,
your program does not need to handle the case where it takes more
than one truck load to supply one food pantry.
- Assume the truck will deliver the complete allocation for a
food pantry in one load. That is, it won't deliver part of the allocation
in one load then the rest in another load. For example, if each
food pantry gets 100 boxes and the truck can hold 330, the truck will
be loaded with 300 boxes to deliver the full allocation to 3 food
pantries. So a "full" load will be 300 even though the truck could
hold 330.
- The amount of space left in a full truck should be the
number of cubic feet of space remaining (not the number of
extra boxes that could fit).
- It takes approximately 35 seconds to load each box in
the truck. When calculating
the hours and minutes disregard any extra seconds.
Sample Output (NOTE: This shows the prompts and input of
24 20 14 for the dimensions (length, width, height)
of the box; 2000 for the number of boxes donated.
Food Bank Distribution
======================
Enter size of each box donated ---
length, width, height (in inches): 24 20 14
Enter the number of boxes donated: 2000
Distribution Planning Information
*********************************
Box size (in inches): 24.0 by 20.0 by 14.0
Number of boxes donated: 2000
Number of boxes that will fit in the truck: 308
Number of boxes each local food pantry should receive: 133
Number of leftover boxes: 5
Number of food pantries served by one truck load: 2
Number of truck loads needed: 8
Number of boxes in a "full" load: 266
Number of cubic feet of unused space in a "full" truck: 404.149
Estimated time to load a full truck: 2 hours, 35 minutes
Requirements:
- 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 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 (emacs helps you do this - it automatically
indents in most cases -- if a line isn't indented correctly go to it
and press TAB OR select the whole program using CTRL-x, CTRL-p then
use ALT-CTRL-\. If TAB doesn't make it indent correctly you probably have
a syntax error).
- Document your program. At the top you must have documentation that
includes the file name, a brief description of
what the program does (this MUST include a list of the input expected
and the output the program will produce), the date, and your name.
Use inline documentation to document each major section of code. However,
don't document every line!!
Warning: A program that does not compile will receive at most
20% on the assignment even if the error is a small one preventing
compilation.
Submission
- Hand In: A printed copy of your program (the source code).
- Electronic Submission: Create a tar file,
named yourNameAssn1.tgz, of the directory
containing your program and copy the file to ~ingram/CPSC120A/yourname
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.