//Created by mk 11.1.09 Last updated 11.5.09 (v3 to v4) import java.util.Scanner; //Import Scanner import java.text.NumberFormat; //Import NumberFormat for rounding public class Calculator //Class declaration { static Scanner scan = new Scanner(System.in); //Scanner name = scan static NumberFormat nf = NumberFormat.getNumberInstance(); //NumberFormat name = nf public static void main(String []args) //Main method { int roundInp1; //Input for lines 17-21 (Select type of rounding) int roundInp2; //Input for lines 28-48 (Select decimal places for rouding) System.out.println("Calculator by mk. Updated 11.5.09 v4"); //Line 17 System.out.println("\nPress 1 for automatic rounding"); System.out.println("Press 2 for no rounding"); System.out.println("Press 3 to select rounding after every calculation\n\n"); //Line 21 roundInp1 = scan.nextInt(); if (roundInp1 == 1) //Auto rounding { System.out.print("\nWould you like to round to 1, 2, or 3 places? "); roundInp2 = scan.nextInt(); //Line 28 if (roundInp2 == 1) { round1(); } if (roundInp2 == 2) { round2(); } if (roundInp2 == 3) { round3(); } if (roundInp2 < 1 | roundInp2 > 3) { System.out.println("\nFail!"); } //Line 48 } if (roundInp1 == 2) //No rounding, { noRound(); } if (roundInp1 == 3) //Selective rounding { selectRound(); } } //End of main Method public static void round1() //Auto rounding to 1 place { double add, sub, mult, div, rem; double power1, power2, power3, sqr1, sqr2; double abs1, abs2; //For calculating input double inp1, inp2; //Input of values int inp3; //Choses operator power3 = 2; while (true) //Loop { System.out.print("\nPlease enter the first value: "); inp1 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp1); System.out.print("\nPlease enter the second value: "); inp2 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp2); System.out.println("\nThe values you have entered are: " + inp1 + " & " + inp2); System.out.println("\n/////////\\\\\\\\\\\\\\\\\\ "); System.out.println("Enter a operation:"); System.out.println("\\\\\\\\\\\\\\\\\\/////////"); System.out.println("\nPress 1 for Addition"); System.out.println("Press 2 for Subraction"); System.out.println("Press 3 for Multiplication"); System.out.println("Press 4 for Division"); System.out.println("Press 5 for the Remainder from division"); System.out.println("Press 6 for the square of value 1"); System.out.println("Press 7 for the square of value 2"); System.out.println("Press 8 for the square root of value 1"); System.out.println("Press 9 for the square root of value 2"); System.out.println("Press 10 for the absolute value of value 1"); System.out.println("Press 11 for the absolute value of value 2\n"); inp3 = scan.nextInt(); if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of loop } //End of method public static void round2() //Auto rounding to 2 places { double add, sub, mult, div, rem; double power1, power2, power3, sqr1, sqr2; double abs1, abs2; //For calculating input double inp1, inp2; //Input of values int inp3; //Choses operator power3 = 2; while (true) //Loop { System.out.print("\nPlease enter the first value: "); inp1 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp1); System.out.print("\nPlease enter the second value: "); inp2 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp2); System.out.println("\nThe values you have entered are: " + inp1 + " & " + inp2); System.out.println("\n/////////\\\\\\\\\\\\\\\\\\ "); System.out.println("Enter a operation:"); System.out.println("\\\\\\\\\\\\\\\\\\/////////"); System.out.println("\nPress 1 for Addition"); System.out.println("Press 2 for Subraction"); System.out.println("Press 3 for Multiplication"); System.out.println("Press 4 for Division"); System.out.println("Press 5 for the Remainder from division"); System.out.println("Press 6 for the square of value 1"); System.out.println("Press 7 for the square of value 2"); System.out.println("Press 8 for the square root of value 1"); System.out.println("Press 9 for the square root of value 2"); System.out.println("Press 10 for the absolute value of value 1"); System.out.println("Press 11 for the absolute value of value 2\n"); inp3 = scan.nextInt(); if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of loop } //End of method public static void round3() //Auto rounding to 3 places { double add, sub, mult, div, rem; double power1, power2, power3, sqr1, sqr2; double abs1, abs2; //For calculating input double inp1, inp2; //Input of values int inp3; //Choses operator power3 = 2; while (true) //Loop { System.out.print("\nPlease enter the first value: "); inp1 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp1); System.out.print("\nPlease enter the second value: "); inp2 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp2); System.out.println("\nThe values you have entered are: " + inp1 + " & " + inp2); System.out.println("\n/////////\\\\\\\\\\\\\\\\\\ "); System.out.println("Enter a operation:"); System.out.println("\\\\\\\\\\\\\\\\\\/////////"); System.out.println("\nPress 1 for Addition"); System.out.println("Press 2 for Subraction"); System.out.println("Press 3 for Multiplication"); System.out.println("Press 4 for Division"); System.out.println("Press 5 for the Remainder from division"); System.out.println("Press 6 for the square of value 1"); System.out.println("Press 7 for the square of value 2"); System.out.println("Press 8 for the square root of value 1"); System.out.println("Press 9 for the square root of value 2"); System.out.println("Press 10 for the absolute value of value 1"); System.out.println("Press 11 for the absolute value of value 2\n"); inp3 = scan.nextInt(); if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of loop } //End of method public static void noRound() //No rounding at all { double add, sub, mult, div, rem; double power1, power2, power3, sqr1, sqr2; double abs1, abs2; //Variables to calculate double inp1, inp2; //Input for 2 vaules being calculated int inp3; //Input for which operator power3 = 2; while (true) //Loop statement { System.out.print("\nPlease enter the first value: "); inp1 = scan.nextDouble(); //First value System.out.println("\nYou have entered: " + inp1); System.out.print("\nPlease enter the second value: "); inp2 = scan.nextDouble(); //Second value System.out.println("\nYou have entered: " + inp2); System.out.println("\nThe values you have entered are: " + inp1 + " & " + inp2); System.out.println("\n/////////\\\\\\\\\\\\\\\\\\ "); System.out.println("Enter a operation:"); System.out.println("\\\\\\\\\\\\\\\\\\/////////"); System.out.println("\nPress 1 for Addition"); System.out.println("Press 2 for Subraction"); System.out.println("Press 3 for Multiplication"); System.out.println("Press 4 for Division"); System.out.println("Press 5 for the Remainder from division"); System.out.println("Press 6 for the square of value 1"); System.out.println("Press 7 for the square of value 2"); System.out.println("Press 8 for the square root of value 1"); System.out.println("Press 9 for the square root of value 2"); System.out.println("Press 10 for the absolute value of value 1"); System.out.println("Press 11 for the absolute value of value 2\n"); inp3 = scan.nextInt(); //Input for operator if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); add = inp1+inp2; System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + add); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; System.out.println("\nThe answer is: " + sub); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; System.out.println("\nThe answer is: " + mult); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; System.out.println("\nThe answer is: " + div); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; System.out.println("\nThe answer is: " + rem); } if(inp3 < 1 | inp3 > 9) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; System.out.println("\nThe answer is: " + (Math.pow(power1, power3))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; System.out.println("\nThe answer is: " + (Math.pow(power2, power3))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; System.out.println("\nThe answer is: " + (Math.sqrt(sqr1))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; System.out.println("\nThe answer is: " + (Math.sqrt(sqr2))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; System.out.println("\nThe answer is: " + (Math.abs(abs1))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; System.out.println("\nThe answer is: " + (Math.abs(abs2))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of loop } //End of method public static void selectRound() //Selective rounding { double add, sub, mult, div, rem; double power1, power2, power3, sqr1, sqr2; double abs1, abs2; //For calculating input double inp1, inp2; //Input of values int inp3; //Choses operator int inp4; //Selects rounding or not int inp5; //Select decimal places ot round to power3 = 2; while (true) //Loop { System.out.print("\nPlease enter the first value: "); inp1 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp1); System.out.print("\nPlease enter the second value: "); inp2 = scan.nextDouble(); System.out.println("\nYou have entered: " + inp2); System.out.println("\nThe values you have entered are: " + inp1 + " & " + inp2); System.out.println("\n/////////\\\\\\\\\\\\\\\\\\ "); System.out.println("Enter a operation:"); System.out.println("\\\\\\\\\\\\\\\\\\/////////"); System.out.println("\nPress 1 for Addition"); System.out.println("Press 2 for Subraction"); System.out.println("Press 3 for Multiplication"); System.out.println("Press 4 for Division"); System.out.println("Press 5 for the Remainder from division"); System.out.println("Press 6 for the square of value 1"); System.out.println("Press 7 for the square of value 2"); System.out.println("Press 8 for the square root of value 1"); System.out.println("Press 9 for the square root of value 2"); System.out.println("Press 10 for the absolute value of value 1"); System.out.println("Press 11 for the absolute value of value 2\n"); inp3 = scan.nextInt(); //Operator input System.out.print("\nWould you like to round? (1-Yes 2-No) "); inp4 = scan.nextInt(); //Rounding input if (inp4 == 1) //Yes to rounding { System.out.print("\nTo 1, 2, or 3 places? "); inp5 = scan.nextInt(); //Input for decimal places if (inp5 == 1) //1 place { if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(1); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of if (inp5 == 1) if (inp5 == 2) //if 2 places { if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(2); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of if (inp5 == 2) if (inp5 == 3) //3 places { if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); add = inp1+inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(add))); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); sub = inp1-inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(sub))); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); mult = inp1*inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(mult))); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); div = inp1/inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(div))); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); rem = inp1%inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(rem))); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power1, power3)))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.pow(power2, power3)))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr1)))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.sqrt(sqr2)))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs1)))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; nf.setMinimumFractionDigits(0); nf.setMaximumFractionDigits(3); System.out.println("\nThe answer is: " + (nf.format(Math.abs(abs2)))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of if (inp5 == 3) } //End of if (inp4 == 1) if (inp4 == 2) //If no rounding { if (inp3 == 1) //Addition { System.out.println("\nYou have entered Addition"); System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + (inp1+inp2)); } if (inp3 == 2) //Subtraction { System.out.println("\nYou have entered Subtraction"); System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + (inp1-inp2)); } if (inp3 == 3) //Multiplication { System.out.println("\nYou have entered Multiplication"); System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + (inp1*inp2)); } if (inp3 == 4) //Division { System.out.println("\nYou have entered Division"); System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + (inp1/inp2)); } if (inp3 == 5) //Remainder { System.out.println("\nYou have entered Remainder"); System.out.println("for the values of " + inp1 + " & " + inp2); System.out.println("\nThe answer is: " + (inp1%inp2)); } if (inp3 == 6) //Square of inp1 { System.out.println("\nYou have entered square "); System.out.println("for the value of " + inp1); power1 = inp1; System.out.println("\nThe answer is: " + (Math.pow(power1, power3))); } if (inp3 == 7) { System.out.println("\nYou have entered square"); System.out.println("for the value of " + inp2); power2 = inp2; System.out.println("\nThe answer is: " + (Math.pow(power2, power3))); } if (inp3 == 8) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp1); sqr1 = inp1; System.out.println("\nThe answer is: " + (Math.sqrt(sqr1))); } if (inp3 == 9) { System.out.println("\nYou have entered square root"); System.out.println("for the value of " + inp2); sqr2 = inp2; System.out.println("\nThe answer is: " + (Math.sqrt(sqr2))); } if (inp3 == 10) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp1); abs1 = inp1; System.out.println("\nThe answer is: " + (Math.abs(abs1))); } if (inp3 == 11) { System.out.println("\nYou have absolute value"); System.out.println("for the value of " + inp2); abs2 = inp2; System.out.println("\nThe answer is: " + (Math.abs(abs2))); } if(inp3 < 1 | inp3 > 11) //For those that fail { System.out.println("\nYou fail! Read teh instructions!"); } } //End of if (inp4 == 2) } //End of loop } //End of method } //End of class