Results 1 to 5 of 5
Thread: In need of assistance!
- 01-21-2012, 03:43 AM #1
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
In need of assistance!
Hello all.
I am completely confused over an assignment I am working on and hope I can be pointed in the right directions.
For the assignment I have to write a program that prompts a user through a GUI to enter the name and weight of four objects. Then the code needs to calculate the weight of the objects on the Earth, Mercury, Moon and Jupiter. So:
Mercury weight = Earth weight * .378
Moon weight = Earth weight * .166
Jupiter weight = Earth weight * 2.364
I must us an array to store the object's weights and its names.
It has been extremely slow going as I am completely new to the world of Java. I have been trying to go step-by-step with this. So far I have this:
So far I have managed to set it up where it at least comes up to prompt for a name then a weight, then displays the inputs 4 times for earth. Not even sure if that is how it is suppose to go. I would really like it to take the inputs and display all the results at the same time (totally not sure how to do that). What I'm confused about now is do I create a method in this class for calculation of the other planets? I am really not even sure where to go from here so any directions would be greatly appreciated.Java Code:package guiprogrampart1; import javax.swing.JOptionPane; public class GuiProgramPart1 { Weight [] object; public static void main(String[] args) { Weight [] object = new Weight[4]; for (int i = 0; i <object.length; i++) { String ObjectName = JOptionPane.showInputDialog( "What is the Objects name?" ); String ObjectWeight = JOptionPane.showInputDialog( "What is the Objects Weight?" ); // display result in a JOptionPane message dialog JOptionPane.showMessageDialog( null, "The " + ObjectName + " weighs " + ObjectWeight + " on Earth", "Weight of Object", JOptionPane.PLAIN_MESSAGE ); } } }
- 01-21-2012, 04:02 AM #2
Re: In need of assistance!
If you would like the output to all display like that I would recommend taking the Message Dialog code out of the FOR loop that you have set up. Since every time that it goes through that loop it will be outputting the Earth weight. Also, your prompts although correct are not being put into specific slots in your array. You are just simply assigning them to a string. You must assign it so that it is going into your array instead. Hope this helps a little to get you started again.
Sincerely, Joshua Green
Please REP if I help :)
- 01-21-2012, 04:15 AM #3
Member
- Join Date
- Jan 2012
- Posts
- 2
- Rep Power
- 0
Re: In need of assistance!
Thank you Josh for your response. Now by removing MessageDialog out of the FOR loop I can only assume you basically mean moving the "}" above that line. When I do this the ObjectName and ObjectWeight are not being recognized (within the MessageDialog). Is there a method that I have to include with the MessageDialog in order to recognize these?
- 01-21-2012, 12:39 PM #4
Re: In need of assistance!
Why do you have the array? You don't seem to use it. You should be saving the user's input in those arrays.
- 01-26-2012, 01:40 AM #5
Re: In need of assistance!
Also, are you trying to accomplish this using a plain array? Or were you trying to initiate an array of objects. Let me try to explain further... Do you want the objects name AND the objects weight to be stored in the same slot in the array? Or does it matter? Just trying to get some more info on what you want to do.
Sincerely, Joshua Green
Please REP if I help :)
Similar Threads
-
assistance needed
By teardrop3903 in forum New To JavaReplies: 5Last Post: 04-18-2011, 03:30 AM -
Assistance about this.
By Syfer in forum Advanced JavaReplies: 38Last Post: 06-21-2010, 05:59 PM -
Game assistance.
By Sean_J in forum New To JavaReplies: 2Last Post: 03-16-2010, 04:05 PM -
Looking for assistance
By s_dawg101 in forum New To JavaReplies: 32Last Post: 11-04-2009, 02:49 AM -
In need of some assistance
By Boer84 in forum New To JavaReplies: 2Last Post: 07-08-2008, 04:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks