Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 01-30-2008, 08:10 PM   #1
Member (10 bit)
 
faint545's Avatar
 
Join Date: Mar 2006
Location: Maryland
Posts: 550
Question Java Help

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
faint545 is offline   Reply With Quote
Old 01-30-2008, 08:34 PM   #2
Member (11 bit)
 
Lespaul20's Avatar
 
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
Lespaul20 is offline   Reply With Quote
Old 01-30-2008, 08:52 PM   #3
Member (10 bit)
 
faint545's Avatar
 
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.
faint545 is offline   Reply With Quote
Old 01-30-2008, 10:58 PM   #4
Member (11 bit)
 
Lespaul20's Avatar
 
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
Lespaul20 is offline   Reply With Quote
Old 01-30-2008, 11:41 PM   #5
Member (10 bit)
 
faint545's Avatar
 
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....
faint545 is offline   Reply With Quote
Old 01-31-2008, 09:10 AM   #6
Member (13 bit)
 
Floppyman's Avatar
 
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
Floppyman is offline   Reply With Quote
Old 01-31-2008, 09:11 AM   #7
Member (11 bit)
 
Lespaul20's Avatar
 
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?
Lespaul20 is offline   Reply With Quote
Old 01-31-2008, 10:01 PM   #8
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
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.
Force Flow is offline   Reply With Quote
Old 02-20-2008, 07:37 PM   #9
Member (10 bit)
 
faint545's Avatar
 
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.
faint545 is offline   Reply With Quote
Old 02-20-2008, 09:01 PM   #10
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
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.
Force Flow is offline   Reply With Quote
Old 02-21-2008, 04:26 PM   #11
Member (10 bit)
 
faint545's Avatar
 
Join Date: Mar 2006
Location: Maryland
Posts: 550
how do you get the JLabels to format correctly? having one below the other...
faint545 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -5. The time now is 07:34 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2