I am not sure if I am using public static int correctly as well. All in all I feel like this code is a giant mess where I just kept adding more and more to it that I probably don't need, but this point I still cant quite figure out how to get it to loop the way I want it to.
import java.util.Scanner;
public class Program7 {
public static void main(String[] args) {
// main menu
mm();
int choice = 0;
switch (choice) {
// addition
case 1:
add();
break;
// subtraction
case 2:
sub();
break;
// exit
case 3:
System.out.print("GOOD BYE ^__^");
break;
// if choice >3 or <1
default:
System.out.print("\nInvalid selection.\nPlease select from (1-3): ");
Scanner kb = new Scanner(System.in);
choice = kb.nextInt();
}
}
addition
public static int add() {
System.out.print("\nEnter number1: ");
Scanner kb = new Scanner(System.in);
int num1 = kb.nextInt();
System.out.print("Enter number2: ");
int num2 = kb.nextInt();
int sum = num1 + num2;
System.out.print("\n" + num1 + " + " + num2 + " = " + sum);
return sum;
}
subtraction
public static int sub() {
System.out.print("Enter number1: ");
Scanner kb = new Scanner(System.in);
int num1 = kb.nextInt();
System.out.print("Enter number2: ");
int num2 = kb.nextInt();
int diff = num1 - num2;
System.out.print(num1 + " - " + num2 + " = " + diff);
return diff;
}
main menu for invalid number (<1 or >3) and/or after user finishes their choice until they select choice number 3:
public static int mm() {
System.out.print("==MAIN MENU==\n1.Addition\n2.Subtraction\n3.Exit\n\nSelect Menu(1-3): ");
Scanner kb = new Scanner(System.in);
int choice = kb.nextInt();
return choice;
}