There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Java Help


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
Animesing's Avatar
Member with 44 posts.
 
Join Date: Oct 2004
26-Sep-2007, 02:32 PM #1
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>

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:27 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.