Not sure how to call the methods in this program.

import javax.swing.JOptionPane;

public class Main_Class {
	
	private static final char Y = 0;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

			/**
			 * @param args
			 */
				// declare variables
				int input1, input2, sum, diff, product, average, absolute, max, min, adjusted1, adjusted2, newSum;
				
				// welcome message
				JOptionPane.showMessageDialog(null, "By Charles Hughes, " +
					"Class CIS247B.\nThis program asks for two intergers, calculates and display their sum, difference, product and average.\n" +
					"Press OK to begin, follow prompts...\n", "NumberGames",JOptionPane.INFORMATION_MESSAGE);

				do {
				// get input
				String number1 = JOptionPane.showInputDialog(null,"Enter first integer","Input for Calculations",
						JOptionPane.QUESTION_MESSAGE); // get first integer
				input1 = Integer.parseInt(number1); // convert first integer from string to integer type
				String number2 = JOptionPane.showInputDialog(null,"Enter second integer","Input for Calculations",
						JOptionPane.QUESTION_MESSAGE); // get second integer
				input2 = Integer.parseInt(number2); // convert second integer from string to integer type
				// do calculations
				sum = input1 + input2; // add integers and initialize sum
				diff = input1 - input2; // subtract integers and initialize diff (for difference)
				product = input1 * input2; // multiply integers and initialize product
				average = sum / 2;
				absolute = (diff < 0) ?  -diff : diff;
				max = (input1 > input2) ? input1 : input2;
				min = (input1 < input2) ? input1 : input2;
				
				// display results
				String output = "The two integers you entered are " + number1 +" and " + number2 + ".\n" +
					"Their sum is " + sum + " ("+ number1 + "+" + number2 + "=" + sum + ").\n" +
					"Their difference is " + diff + " ("+ number1 + "-" + number2 + "=" + diff + ").\n" +
					"Their product is " + product + " ("+ number1 + "x" + number2 + "=" + product + ").\n" +
					"Their average is " + average + " ("+ sum + " divided by 2 = " + average + ").\n" +
					"The absolute value of their difference is " + absolute + ".\n" +
					"The maximum number is " + max + ".\n" +
					"The minimum number is " + min + "." ;
				JOptionPane.showMessageDialog(null, output, "Output",JOptionPane.INFORMATION_MESSAGE);	
						
				// if both numbers are greater than 100, then subtract 100 from each.
				if (input1 > 100 && input2 > 100) {
					adjusted1 = input1 - 100;
					adjusted2 = input2 - 100;
					String output2 = "Both interger values are greater than 100, therefore their values have been adjusted as follows:\n" +
						"The first integer's value is now " + adjusted1 + ". ("+ input1 + " - 100).\n" + 
						"The second integer's value is now " + adjusted2 + ". ("+ input2 + " - 100)."; 
					JOptionPane.showMessageDialog(null, output2, "Output",JOptionPane.INFORMATION_MESSAGE);	
				}	
				// if both numbers are negative, then add 200 to their sum.		
				if (input1 < 0 && input2 < 0) {
					newSum = sum + 200;
					String output2 = "Both interger values are negative, therefore their sum has been adjusted as follows:\n" +
						"200 has been added to the sum of both integers. (" + input1 + " + " + input2 +" + 200 = " + newSum + ")"; 
					JOptionPane.showMessageDialog(null, output2, "Output",JOptionPane.INFORMATION_MESSAGE);			
				}
				System.out.println("continue loop");
				} while ( JOptionPane.showConfirmDialog(null, "Do it again?") == JOptionPane.YES_OPTION);
				
				String output3 = "Thank you for using my program.";
				JOptionPane.showMessageDialog(null, output3, "Output",JOptionPane.INFORMATION_MESSAGE);	
	}
				private static String sumString(int number1, int number2)
				{
					String sumOutput = " The sum is: " + number1 + " + "
					+ number2 + " = " + (number1 + number2) + "\n";

					return sumOutput;
				}
				private static String differenceString(int number1, int number2)
				{
					String  differenceOutput = " The difference is: " + number1 + "-" + number2 + "=" + (number1 - number2) + "\n";
					return differenceOutput;
				}
				private static String productString(int number1, int number2)
				{
					String productOutput = " The product is: " + number1 + "*" + number2 + "=" + (number1 * number2) + "\n";
					return productOutput;
 				} 
				private static void averageString(int number1, int number2)
				{
					String averageOutput = " The average is: " + number1 + "+" + number2 + " divided by 2 = " + number1 + number2 /2 + ").\n";
				}
				
	}

private methods are called in exactly the same way as public methods with one difference - you can only call them from within the class that owns them. So , to call the sumString method from the main method for example, you can do the following:

public static void main(String[] args)
{
  // ...
  String myString = sumString(3,5);
  // ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.