View Full Version : Java Help
faint545
01-30-2008, 09:10 PM
I've ran into a bit of a problem... I'm writing a pretty simple Java program for my class. The program only understand how to calculate three different types of surface areas. The surface areas of a sphere, torus, and a box. This is what I have so far in my source code: http://i31.tinypic.com/2nsn804.jpg. As you can see, I tested my loop to see if it would work, but all it doesn't seem to work. I can't figure out why. This is my first attempt at Java, most of my programming background is in C++.
Lespaul20
01-30-2008, 09:34 PM
Your formula doesn't seem right.
Also, PI is a constant that is part of the Math class.
faint545
01-30-2008, 09:52 PM
how would I retrieve the pi constant? btw, we can only use one class.
i'm pretty sure my formula is correct. it's the one my professor asked us to use.
Lespaul20
01-30-2008, 11:58 PM
For PI
You have to import java.lang.math
then
"public final static double PI" to use it
According to this
http://en.wikipedia.org/wiki/Torus
This is the formula for the area of a Torus
(2πr)(2πR) Where r = radius of cylinder, R = radius of Torus
faint545
01-31-2008, 12:41 AM
okay. i figured out why my loop wasnt working correctly. i used a semi colon right after the loop expression. got rid of that. but now the loop still doesnt work....
Floppyman
01-31-2008, 10:10 AM
Can you give a bit more detail? What part of the loop does not work? Does it not execute properly, or does it not provide the right answer, or? I'd be happy to help you debug, but I need a little bit more information as to what you are trying to accomplish.
HTH
Lespaul20
01-31-2008, 10:11 AM
What is it not doing? Have you tried debug mode to see where it's going wrong?
Force Flow
01-31-2008, 11:01 PM
PI is part of the math library. No need to specify a variable for it.
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Math.html
Without actually running it, I'm guessing you're getting an infinite loop?
I'd suggest copying the "system.out.println", the "system.out.print" and the "solidsurface =" lines and put them as the last lines in the while loop.
Second, with strings, you have to use the .equals() method, rather than ==.
So,
while(mystring1.equals(mystring2){
loopstuff();
}
Suggestion for making this app better: use a menu so you type in a number or letter instead of an entire word...it's less error prone.
faint545
02-20-2008, 08:37 PM
I have another problem... this time it deals with GUI. The assignment:
Create a program with a GUI interface that calculates the income of a movie theater. The user will enter in the number of items sold. Then the program will then determine the income for each item.
Here is a screen shot of what it's supposed to look like... http://i30.tinypic.com/97l101.jpg
Now here's my problem... I'm not sure on how implement the classes. The teacher wants 3 different classes (Cost class which will store the amount for each item, a frame and panel class).
This is what I have so far.... 7247. I just cant seem to figure out how to create separate subpanels for each item (Adult, Child, Drink ect..) and make then align.
Force Flow
02-20-2008, 10:01 PM
I haven't dealt with swing in years, but I seem to dimly recall you may be able to create panels within panels.
Although, I think 3 would be enough (left section, right section, and the lower section with the 3 buttons)
[edit]: Actually, take a look at Container, as well as JPanel.
faint545
02-21-2008, 05:26 PM
how do you get the JLabels to format correctly? having one below the other...
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.