Assignment 01 -- Aquarium Cost Estimator The Lake Superior Aquarium Company has
ID: 3782361 • Letter: A
Question
Assignment 01 -- Aquarium Cost Estimator
The Lake Superior Aquarium Company has commissioned a web application, to assist in estimating production costs for their custom-built aquariums.
The client manufactures custom aquariums and has identified a formula for estimating the overall cost of materials and labor. This formula takes tank dimensions (height, width, depth) as input. After attempting to produce this application in-house, the client has decided to contract out the remaining work.
The business logic is documented within the application code and needs to be implemented.
(See attached file index.php.txt)
Explanation / Answer
<?php
// Variables are identified with a dollar sign:
$a = 5;
// -------------------------------------------------------
// Your assignment is to calculate the following values...
$materials_cost = 0; // cost of materials: glass, fish, water, etc
$labor_cost = 0; // cost of putting it together
$total_cost = 0; // the grand total
$time_required = 0; // the total number of hours required
$total_fish = 0; // total fish in a fully-stocked tank
$regular_fish = 0;
$fancy_fish = 0;
// here is the input... (no changes needed here)
$width = intval(@$_REQUEST['width']);
$height = intval(@$_REQUEST['height']);
$depth = intval(@$_REQUEST['depth']);
// you can set the following variable to a string, to report any errors at the end.
//$error='';
$continue = FALSE;
// validate width
if ( $width <= 0 ) {
$error = 'Width must be greater than zero.';
// validate height
} else if ( $height <= 0 ) {
$error = 'Height must be greater than zero.';
// validate depth
} else if ( $depth <= 0 ) {
$error = 'Depth must be greater than zero.';
} else {
$error='';
$continue = TRUE;
}
// Example: $error='Width cannot be a negative number.';
// START WORKING HERE...
// Part 1: Materials Cost
/*
A. Start by finding the total surface area of the aquarium. Assume that the aquarium is glass on all six sides. Store this as $glass_surface. Hint: (W*H)*2 + (W*D)*2 + (H*D)*2
B. Also find the total volume of the aquarium, and store as $total_volume. Assume the tank will be filled completely to the top.
C. Raw materials cost: glass costs $0.03 per cm/sq.
D. Raw materials cost: purified water costs $0.001 per cm3 (cubic centimeter).
E. Each fish requires 275 cm3 of space. Find the maximum number of fish that can fit in the tank. ** Hint: use the floor() function to round down.
F. NOT more than 7% of the fish will be fancy fish ($1.98 each). There must be an even number of fancy fish. Add as many fancy fish as possible. The rest will be regular fish ($0.61 each).
G. Add a small castle and lighting: $7.95
H. The sum of C,D,F,and G and the total materials cost.
*/
if ($continue){
$glass_surface = ($width*$height)*2 + ($width*$depth)*2 + ($height*$depth)*2;
$total_volume = $width*$depth*$height;
$total_fish = $total_volume/275;
$total_fish = floor($total_fish);
$fancy_fish = $total_fish * 0.07;
$fancy_fish = floor($fancy_fish);
//must have an even amount of fancy fish
if (!(($fancy_fish % 2) === 0)){
$fancy_fish -= 1;
}
// in case total fish is < 1
if ($total_fish < 1){
$total_fish = 0;
$fancy_fish = 0;
}
$regular_fish = $total_fish - $fancy_fish;
$materials_cost =
//cost of glass
($glass_surface * 0.03) +
//cost of water
($total_volume * 0.001) +
//cost of fancy fish
($fancy_fish * 1.98) +
//cost of regular fish
($regular_fish * 0.61) +
//cost of small castle and lighting
7.95;
}
echo $error;
if($width==0) $width='';
if($height==0) $height='';
if($depth==0) $depth='';
?>
<form method='get' action='index.php'>
<table border='1'>
<tr>
<th colspan='2'>Aquarium Cost Estimator</th>
</tr>
<tr>
<td>Width</td>
<td><input type='text' name='width' value='<?=$width?>' size='5'/> cm</td>
</tr>
<tr>
<td>Height</td>
<td><input type='text' name='height' value='<?=$height?>' size='5'/> cm</td>
</tr>
<tr>
<td>Depth</td>
<td><input type='text' name='depth' value='<?=$depth?>' size='5'/> cm</td>
</tr>
<tr>
<td> </td>
<td><input type='submit' value='Calculate'/></td>
</tr>
<tr>
<th colspan='2'>Results</th>
</tr>
<tr>
<td>Total Fish</td>
<td><?php if($total_fish) echo $total_fish.' ('.$fancy_fish.' fancy)'; else echo ' '?></td>
</tr>
<tr>
<td>Materials Cost</td>
<td><?=($materials_cost) ? $materials_cost: ' '?></td>
</tr>
</table>
</form>