123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
-
- import java.util.Scanner;
- /**
- * Created by leon on 2/9/18.
- */
-
- public class Console {
- public void runCommandLoop() {
- Scanner input = new Scanner(System.in);
- //String a = input.nextLine();
- //String b = input.nextLine();
-
- // Calculator calc = new ....
- System.out.println("Gimme some math to do!");
- System.out.println("Enter a command or \"HELP\" for help");
- while (true) {
- try{
- double value = 0;
- String command = input.nextLine();
-
- if (command.equalsIgnoreCase("exit")) {
- System.out.println("Thanks for calculating with us!");
- break;
- }
- else if (command.equalsIgnoreCase("help")) {
- System.out.println(Help.text());
- }
- else if (command.equalsIgnoreCase("dec")) {
- System.out.println("Now working in DECIMAL MODE");
- }
- else if (command.equalsIgnoreCase("bin")) {
- System.out.println("Now working in BINARY MODE");
- }
- else if (command.equalsIgnoreCase("hex")) {
- System.out.println("Now working in HEXIDECIMAL MODE");
- }
- else if (command.equalsIgnoreCase("Oct")) {
- System.out.println("Now working in OCTAL MODE");
- }
- else if (command.equalsIgnoreCase("rad")) {
- System.out.println("RADIANS");
- }
- else if (command.equalsIgnoreCase("deg")) {
- System.out.println("DEGREES");
- }
- else if (command.equalsIgnoreCase("units next")) {
- //rotate units to next
- }
- else if (command.equalsIgnoreCase("add")) {
- System.out.println("Please input first number");
- double i = input.nextDouble();
- System.out.println("Please input second number");
- double j = input.nextDouble();
- value = Functions.add(i, j);
- System.out.println(value);
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("subtract")) {
- System.out.println("Please input first number");
- double i = input.nextDouble();
- System.out.println("Please input second number");
- double j = input.nextDouble();
- value = Functions.subtract(i, j);
- System.out.println(value);
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("multiply")){
- System.out.println("Please input first number");
- double i = input.nextDouble();
- System.out.println("Please input second number");
- double j = input.nextDouble();
- //return
- System.out.println(Functions.multiply(i, j));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("divide")){
- System.out.println("Please input first number");
- double i = input.nextDouble();
- System.out.println("Please input second number");
- double j = input.nextDouble();
- System.out.println(Functions.divide(i,j));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("square")) {
- System.out.println("Please input a number");
- double i = input.nextDouble();
- System.out.println(Functions.square(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("root")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.squareRoot(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("exponent")){
- System.out.println("Please input first number");
- double i = input.nextDouble();
- System.out.println("Please input second number");
- double j = input.nextDouble();
- //return
- System.out.println(Functions.exponent(i, j));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("inverse")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.inverse(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("invert")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.invertSign(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("sin")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.sin(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("cos")) {
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.cos(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("tan")) {
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.tan(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("cot")) {
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.cot(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("sec")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.sec(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("cos")) {
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.csc(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("arcsin")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.arcsin(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("arccos")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.arccos(i));
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("arctan")){
- System.out.println("Please input a number");
- double i = input.nextDouble();
- //return
- System.out.println(Functions.arctan(i));
- System.out.println("Enter a command.");
- }
-
- else if (command.equalsIgnoreCase("addMem")) {
- System.out.println("Adding to memory");
- double i = 0;
- i = Functions.memPlus(i);
- System.out.println(Functions.memPlus(i));
- System.out.println("Enter a command.");
- }
- else if(command.equalsIgnoreCase("clearMem")) {
- System.out.println("Clearing memory");
- double i = 0;
- System.out.println("Memory cleared");
- System.out.println("Enter a command.");
- }
- else if (command.equalsIgnoreCase("recall")) {
- System.out.println(Functions.recall());
- System.out.println("Enter a command.");
- }
- else if(command.equalsIgnoreCase("convert")){
-
- double convert = input.nextDouble();
-
- Conversion.switchDisplay(convert);
- System.out.println("Enter a command.");
- }
- }
- catch(Exception e){
- System.err.print("error!");
- continue;
- }
-
- }
- }
-
- public static void main(String[] args){
- /*Conversion conv = new Conversion();
- Functions c = new Functions();
- c.functions();
- Help h = new Help();
- h.help();*/
- }
- }
|