Java Help I am trying to create a program where when the page loads, a prompt pops up and asks pick a number 1-5 for a shape, then 1 or 2 prompts pop up after that and then ask about either height, length or radius etc. I want those variables to be put in a table and then i want the variables to be put through a set of equations so it can determine the volume, area, etc. I am confused right now, this is as far as i have gotten but now i am stuck and dont know what to do. Suggestions? btw the prompt that goes:
figure = prompt("Please Select a figure from the following list (enter a number):", "1");
dont worry bout that i will add the 5 shapes to that prompt later. Quote:
<html>
<head>
<title>Fun with Geometry</title>
<script type="text/javascript">
document.write('<div style="text-align:center">');
document.write('<h1>');
document.write("Geometry Calculator");
function computeCone(r,h)
//assumes:
//returns:
{ var s,a,v,r;
s = 2*((Math.PI)*r)
s = s.tofixed(2);
a = Math.PI*(Math.pow(r, 2))+Math.PI*r((Math.pow(r, 2)+(Math.pow(h, 2))),0.5);
a = a.tofixed(2);
v = (Math.PI*(Math.pow(r, 2)*h)/3);
v = v.tofixed(2);
r = '"cone.bmp" />';
r = r + "</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + s + "</td><td>";
r = r + a + "</td><td>";
r = r + v;
return r;
}
function computeCube(m)
//assumes:
//returns:
{ var s,a,v,r;
s = 12*m
s = s.tofixed(2);
a = 6*(Math.pow(m, 2))
a = a.tofixed(2);
v = volume=Math.pow(m, 3)
v = v.tofixed(2);
r = '"cube.bmp" />';
r = r + "</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + s + "</td><td>";
r = r + a + "</td><td>";
r = r + v;
return r;
}
function computeCylinder(r,h)
//assumes:
//returns:
{ var s,a,v,r;
s = 4*(Math.PI)*r
s = s.tofixed(2);
a = 2*(Math.PI)*(Math.pow(r, 2))+2*(Math.PI)*r*h
a = a.tofixed(2);
v = Math.PI*(Math.pow(r, 2))*h
v = v.tofixed(2);
r = '"cylinder.bmp" />';
r = r + "</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + s + "</td><td>";
r = r + a + "</td><td>";
r = r + v;
return r;
}
function computePrism(m,h)
//assumes:
//returns:
{ var s,a,v,r;
s = (6*m)+(3*h)
s = s.tofixed(2);
a = ((Math.pow(m, 2))*(Math.pow(3, 0.5)))/(2+3*m*h)
a = a.tofixed(2);
v = (h*(Math.pow(m, 2))*(Math.pow(3, 0,5)))/4
v = v.tofixed(2);
r = '"prism.bmp" />';
r = r + "</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + s + "</td><td>";
r = r + a + "</td><td>";
r = r + v;
return r;
}
function computePyramid(m,h)
//assumes:
//returns:
{ var s,a,v,r;
s = 3*m+(3((Math.pow(m, 2))/(3+(Math.pow(h, 2))),0.5
s = s.tofixed(2);
a = ((Math.pow(m, 2))*(Math.pow(3, 0.5)))/(4+1.5*m*((Math.pow(m, 2)))/(12+Math.pow(h, 2)),0.5
a = a.tofixed(2);
v = h*((Math.pow(m, 2))*(Math.pow(3, 0.5)))/12
v = v.tofixed(2);
r = '"pyramid.bmp" />';
r = r + "</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + "....</td><td>";
r = r + s + "</td><td>";
r = r + a + "</td><td>";
r = r + v;
return r;
}
</script>
</head>
<body>
<script type="text/javascript">
var figure;
figure = parseFloat(figure);
figure = prompt("Please Select a figure from the following list (enter a number):", "1");
switch (figure)
{
case "1":
r = prompt("Please enter the radius of the base (in inches):", "5");
r = parseFloatr;
h = prompt("Please enter the height (in inches):", "8");
h = parseFloath;
var results = computeCone(r,h);
break;
case "2":
m = prompt("Please enter the length of a base edge (in inches):", "3");
m = parseFloatm;
var results = computeCube(m);
break;
case "3":
r = prompt("Please enter the radius of the base (in inches):", "5");
r = parseFloatr;
h = prompt("Please enter the height (in inches):", "8");
h = parseFloath;
var results = computeCylinder(r,h);
break;
case "4":
m = prompt("Please enter the length of a base edge (in inches):", "3");
m = parseFloatm;
h = prompt("Please enter the height (in inches):", "8");
h = parseFloath;
var results = computePrism(m,h);
break;
case "5":
m = prompt("Please enter the length of a base edge (in inches):", "3");
m = parseFloatm;
h = prompt("Please enter the height (in inches):", "8");
h = parseFloath;
var results = computePyrimid(m,h);
break;
default:
Alert("You did not select a valid figure!");
results = '"error.bmp" />';
results = results + "</td>";
results = results + "<td colspan:6>"
results = results + " N/A ";
}
var tableStart
document.write('<table border = 2 align=center cellpadding=5>');
document.write(' <tr>');
document.write(' <td><b> Figure <br /> (inch) </b></td>');
document.write(' <td><b> Radius <br /> (inch) </b></td>');
document.write(' <td><b> Edge <br /> (inch) </b></td>');
document.write(' <td><b> Height <br /> (inch) </b></td>');
document.write(' <td><b> Sum of lengths of edges <br /> (inch) </b></td>');
document.write(' <td><b> Surface area <br /> (inch<sup>2</sup>)</b></td>');
document.write(' <td><b> Volume <br /> (inch<sup>3</sup>) </b></td>');
document.write(' </tr>');
document.write(' <tr>');
document.write(' <td><img src="">
var results
error.bmp
document.write(' <td> N/A </td>');
document.write(' <td> </td>');
document.write(' <td> </td>');
document.write(' <td> </td>');
document.write(' <td> </td>');
document.write(' <td> </td>');
var tableEnd = "</td></table>";
document.write(tableStart + results + tableEnd);
</script>
</body>
</html> | |