Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- String FirstNumber = "1";
- String SecondNumber = "1";
- String method = "add";
- int finalNumber = 0;
- // makes the strings and ints
- FirstNumber = JOptionPane.showInputDialog(null, "What is the First number?");
- SecondNumber = JOptionPane.showInputDialog(null, "What is the Second number?");
- method = JOptionPane.showInputDialog(null, "Would you like to add, subtract, multiply, or divide them? You can also type exit to exit the program.");
- exitProgram(method);
- int firstNumber = Integer.valueOf(FirstNumber);
- int secondNumber = Integer.valueOf(SecondNumber);
- // takes in the inputs
- // sets the string equal to ints
- JOptionPane.showMessageDialog(null,
- "The first number is " + firstNumber + " and the second number is " + secondNumber);
- methodsCalculator(firstNumber, secondNumber, method, finalNumber);
- }
- public static String exitProgram(String method){
- if (method.equals("exit")){
- JOptionPane.showMessageDialog(null, "This program will now shut down");
- System.exit(0);
- }
- //by using the system.exit this program will end if method equals exit
- return method;
- }
- public static int methodsCalculator(int firstNumber, int secondNumber, String method, int finalNumber) {
- // finds the correct method and does the operation
- // it also outputs the result
- if (method.equals("add")) {
- JOptionPane.showMessageDialog(null, "They are going to be Added");
- finalNumber = firstNumber + secondNumber;
- JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
- return finalNumber;
- }
- if (method.equals("subtract")) {
- JOptionPane.showMessageDialog(null, "They are going to be Subtracted");
- finalNumber = firstNumber - secondNumber;
- JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
- return finalNumber;
- }
- if (method.equals("multiply")) {
- JOptionPane.showMessageDialog(null, "They are going to Multiply");
- finalNumber = firstNumber * secondNumber;
- JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
- return finalNumber;
- }
- if (method.equals("divide")) {
- JOptionPane.showMessageDialog(null, "They are going to Divide");
- finalNumber = firstNumber / secondNumber;
- JOptionPane.showMessageDialog(null, "The answer is " + finalNumber);
- return finalNumber;
- }
- else {
- return finalNumber;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement