Hi,
First and foremost, this is not homework (believe it or not some forums freak out about this, so wanted to get this out of the way). I took a Java course in college and want to get back into it. I can do some simple stuff, but am more interested in the basis of object oriented programming (in other words not doing everything in the main method).
Here is the code I'm working with:
import javax.swing.*; public class Experiment { public static void main(String [] args) { String number1 = JOptionPane.showInputDialog(null, "Please enter your first number"); String number2 = JOptionPane.showInputDialog(null, "Please enter your second number"); Double getnumber1 = Double.parseDouble(number1); Double getnumber2 = Double.parseDouble(number2); JOptionPane.showMessageDialog(null, "The number's are " + getnumber1 + "and" + getnumber2); //JOptionPane.showMessageDialog(null, "The numbers added together are" + addNumbers() ); } /* public double addNumbers() { double total; total = getnumber1 + getnumber2; return total; } */ }
What I'm doing
I'm using the JOptionPane simple dialog boxes to try and add together some numbers generated by users. I like JOptionPane, so please don't suggest using Scanner. What I'm trying to do is have the addNumbers part return up to the last JOptionPane message which will show the user the total. I commented out the parts that don't work, the last part of the program and the last JOptionPane message dialog.
What I want to do (ideally) is do all the calculations out of the main method and then be able to call them when needed. So the last part of the code may be totally incorrect (just the commented out part) and the last JOptionPane (also commented out).
So can someone explain to me in simple terms the syntax for calling other methods and such? If I'm totally off base and am doing everything completely wrong, please let me know as well.