/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone {
	public static Scanner input = new Scanner(System.in);
	public static double placeHolder;

	public static void clear() {
		placeHolder = 0.0;
		System.out.println("Save has been deleted, Screen has been cleared.");
	}

	public static void end() {
		System.out.println("Program ended..");
		input.close();
		System.exit(0);
	}

	public static void save(double initValue) {
		System.out.println("Number saved!");
		placeHolder = initValue;
	}

	public static void recall() {
		if (placeHolder != 0) {
			System.out.println("Memory Place Holder Set To: " + placeHolder);
		} else {
			System.out.println("There is no data saved.");
		}
	}

	public static void commands() {
		System.out.println("e = end | c = clear | m = save | r = recall | o = continue");
		String command = input.next();
		if (command.equals("e")) {
			end();
		} else if (command.equals("c")) {
			clear();
		} else if (command.equals("r")) {
			recall();
		}

	}

	public static void main(String[] args) {
		boolean loop = true;
		while (loop == true) {
			commands();
			System.out.println("Please enter what you would like to do: (+,-,*,/,%)");
			String function = input.next();
			System.out.println("Enter the first number to be calucalted (If dividing, this is the numerator):");
			double n1 = input.nextDouble();
			System.out.println("Enter the second number to be calucalted (If dividing, this is the denominator):");
			double n2 = input.nextDouble();

			// =======================
			// Addition
			// =======================
			if (function.equals("+")) {
				double sum = n1 + n2;
				System.out.println(n1 + "+" + n2 + " = " + sum);
				System.out.println("e = end | c = clear | m = save | r = recall");
				String command = input.next();
				// input.nextLine();
				switch (command) {
				case "e":
					end();
					break;
				case "c":
					clear();
					break;
				case "m":
					save(sum);
					break;
				case "r":
					recall();
					break;
				default:
					System.out.println("Default");
					save(sum);
					break;
				}

			}
			// =======================
			// Subtraction
			// =======================
			else if (function.equals("-")) {
				double sum = n1 - n2;
				System.out.println(n1 + "-" + n2 + " = " + sum);
				System.out.println("e = end | c = clear | m = save | r = recall");
				String command = input.next();
				// input.nextLine();
				switch (command) {
				case "e":
					end();
					break;
				case "c":
					clear();
					break;
				case "m":
					save(sum);
					break;
				case "r":
					recall();
					break;
				}
			}
			// =======================
			// Multiplication
			// =======================
			else if (function.equals("*")) {
				double sum = n1 * n2;
				System.out.println(n1 + "*" + n2 + " = " + sum);
				System.out.println("e = end | c = clear | m = save | r = recall");
				String command = input.next();
				// input.nextLine();
				switch (command) {
				case "e":
					end();
					break;
				case "c":
					clear();
					break;
				case "m":
					save(sum);
					break;
				case "r":
					recall();
					break;
				}
			}
			// =======================
			// Division
			// =======================
			else if (function.equals("/")) {
				double sum = n1 / n2;
				System.out.println(n1 + "/" + n2 + " = " + sum);
				System.out.println("e = end | c = clear | m = save | r = recall");
				String command = input.next();
				// input.nextLine();
				switch (command) {
				case "e":
					end();
					break;
				case "c":
					clear();
					break;
				case "m":
					save(sum);
					break;
				case "r":
					recall();
					break;
				}
			}
			// =======================
			// Mod
			// =======================
			else if (function.equals("%")) {
				double sum = n1 % n2;
				System.out.println(n1 + "%" + n2 + " = " + sum);
				System.out.println("e = end | c = clear | m = save | r = recall");
				String command = input.next();
				// input.nextLine();
				switch (command) {
				case "e":
					end();
					break;
				case "c":
					clear();
					break;
				case "m":
					save(sum);
					break;
				case "r":
					recall();
					break;
				}
			}
		}

		// =======================
		// Dictate loop duration:
		// =======================
		System.out.println("Would you like to continue? (Y|N): ");
		String ans = input.nextLine();
		if (ans.equals("N") || ans.equals("n")) {
			System.out.println("Closing Program");
			loop = false;
			end();
		}
	}
}