|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
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++.
__________________
Kerberos2: Corsair Obsidian 700D ASUS M4A89TD Radeon HD 5850 A-DATA 8GB DDR3 1333 AMD Phenom II x6 1055T @ 2.8GHz w/ Corsair H50 Corsair 850HX PSU WD Blue 160GB 7200 RPM SATA HDD WD Black 640GB 7200 RPM SATA HDD ASUS DVD/CD Drive |
|
|
|
|
|
#2 |
|
Member (11 bit)
Join Date: Apr 2003
Location: Iowa
Posts: 1,652
|
Your formula doesn't seem right.
Also, PI is a constant that is part of the Math class.
__________________
LP |
|
|
|
|
|
#3 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
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. Last edited by faint545; 01-30-2008 at 11:10 PM. |
|
|
|
|
|
#4 |
|
Member (11 bit)
Join Date: Apr 2003
Location: Iowa
Posts: 1,652
|
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 |
|
|
|
|
|
#5 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
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....
|
|
|
|
|
|
#6 |
|
Member (13 bit)
Join Date: Mar 1999
Posts: 6,791
|
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 |
|
|
|
|
|
#7 |
|
Member (11 bit)
Join Date: Apr 2003
Location: Iowa
Posts: 1,652
|
What is it not doing? Have you tried debug mode to see where it's going wrong?
|
|
|
|
|
|
#8 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
PI is part of the math library. No need to specify a variable for it.
http://java.sun.com/j2se/1.4.2/docs/...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.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
|
|
#9 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
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.... project3.txt. I just cant seem to figure out how to create separate subpanels for each item (Adult, Child, Drink ect..) and make then align. |
|
|
|
|
|
#10 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
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. |
|
|
|
|
|
#11 |
|
Member (10 bit)
Join Date: Mar 2006
Location: Maryland
Posts: 550
|
how do you get the JLabels to format correctly? having one below the other...
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Java for XP Pro. SP2 ( should I insatll ) | Charlie W | Windows Legacy Support (XP and earlier) | 9 | 02-27-2007 11:44 PM |
| Computer Acronyms | Floppyman | Computer Hardware | 156 | 06-18-2006 06:25 AM |
| newbie needs help with java | scarruth2 | Internet, Web Applications, & The Cloud | 2 | 02-21-2004 04:48 PM |
| Java script works but java applets won't | lexi | Windows Legacy Support (XP and earlier) | 13 | 09-14-2003 07:11 AM |
| Microsoft Wins Stay on Order to Add Java | morriswindgate | General Discussion | 7 | 02-05-2003 09:34 AM |