public
anonymous / AutoCalc.java
Created

AutoCalc by joshellis625

  • Download Gist
AutoCalc.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
// **********************************************
// 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);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.