Created
October 20, 2017 07:54
-
-
Save mentix02/018dbe86aa217d16eec523f7b9ebded0 to your computer and use it in GitHub Desktop.
This file contains 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
import java.util.Scanner; | |
public class Calculator{ | |
public static void cout(String text){ | |
System.out.print(text); | |
} | |
public static int menu(){ | |
Scanner get = new Scanner(System.in); | |
System.out.println("What would you like to do?\n1. Add\n2. Subtract\n3. Multiply\n4. Divide\n5. Exit"); | |
System.out.print("> "); | |
int option = get.nextInt(); | |
return option; | |
} | |
public static void input(){ | |
System.out.print("Enter number : "); | |
} | |
public static float basic(int opt, float x, float y){ | |
cout("Basic module.\n"); | |
switch(opt){ | |
case 1: | |
return (x + y); | |
case 2: | |
return (x - y); | |
default: | |
System.out.println("You're honestly a moron."); | |
return 0; | |
} | |
} | |
public static float complex(int opt, float x, float y){ | |
cout("Complex module.\n"); | |
switch (opt) { | |
case 3: | |
return (x * y); | |
case 4: | |
return (x / y); | |
default: | |
System.out.println("You're honestly a moron."); | |
return 0; | |
} | |
} | |
public static void main(String args[]){ | |
Scanner sc = new Scanner(System.in); | |
float result, x ,y; | |
int option = menu(); | |
if (option >= 0 && option <= 4) { | |
input(); | |
x = sc.nextFloat(); | |
input(); | |
y = sc.nextFloat(); | |
if (option <= 2 && option >= 0) { | |
result = basic(option, x, y); | |
System.out.println("Answer : " + result); | |
} | |
else if (option > 2 && option <= 4){ | |
result = complex(option, x, y); | |
System.out.println("Answer : " + result); | |
} | |
} | |
else{ | |
System.out.println("Exit."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment