Created
September 9, 2012 00:32
-
-
Save anonymous/3681606 to your computer and use it in GitHub Desktop.
AutoCalc by joshellis625
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ********************************************** | |
// Created by: Joshua Ellis (joshellis625) | |
// | |
// Solve multiple simple math problems with two | |
// user inputted numbers | |
// ********************************************** | |
import java.util.Scanner; | |
public class AutoCalc { | |
//Declare variables | |
public static int X, Y; | |
public static int SUM; | |
public static int DIFF; | |
public static float DIV; | |
public static int MULT; | |
public static void main(String[] args) { | |
getInput(); | |
System.out.println(); | |
System.out.println("Let's do some math using the numbers " + X + " and " + Y + "!"); | |
System.out.println(); | |
System.out.println("The sum of " + X + " and " + Y + " is " + getSum()); | |
System.out.println("The difference between " + X + " and " + Y + " is " + getDiff()); | |
System.out.println(X + " divided by " + Y + " is " + getDivide()); | |
System.out.println(X + " times " + Y + " is " + getMultiply()); | |
} | |
//create new Scanner input and convert String to Int | |
public static void getInput() { | |
while(true) { | |
try { | |
Scanner input = new Scanner(System.in); | |
//Apply String input to variables xString and yString | |
System.out.print("Input first number: "); | |
String X_STRING = input.next(); | |
System.out.print("Input second number: "); | |
String Y_STRING = input.next(); | |
//Convert Strings to Integers | |
X = Integer.parseInt(X_STRING); | |
Y = Integer.parseInt(Y_STRING); | |
break; | |
} catch (NumberFormatException nfe) { | |
System.err.println("I said enter numbers..."); | |
} | |
} | |
} | |
public static int getSum() { | |
SUM = X + Y; | |
return(SUM); | |
} | |
public static int getDiff() { | |
DIFF = X - Y; | |
return(DIFF); | |
} | |
public static float getDivide() { | |
DIV = (float)X / (float)Y; | |
return(DIV); | |
} | |
public static int getMultiply() { | |
MULT = X * Y; | |
return(MULT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment