123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
-
- /**
- * Write a description of class Cal here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.io.IOException;
- import java.util.Scanner;
- import java.util.*;
- public class Cal{
- public static void main (String[]args){
- // instance variables - replace the example below with your own
- Scanner scan = new Scanner(System.in);
- double calcValue1;
- double calcValue2;
- double addTwoNumbers;
- double getCalcValue;
- int options = 0;
-
- double answer;
- double sum;
- boolean off = false;
- boolean on = true;
- int num1 =0;
- int num2 =0;
-
-
- System.out.print("Let's crunch some numbers");
- while (on){
-
- System.out.println("Please enter the number of what you want to do");
- System.out.println("1. Add ");
- System.out.println("2. Substract");
- System.out.println("3. Multiply ");
- System.out.println("4. Division");
- System.out.println("5. Modulus ");
- System.out.println("6. Square Root");
- System.out.println("7. Avg");
- System.out.println("8. Exp");
- System.out.println("9. Mode");
- System.out.println("10. Max");
- System.out.println("11. Min");
- System.out.println("12. Abs");
- System.out.println("13. Round");
- System.out.println("14. Sin");
- System.out.println("15. Cos");
- System.out.println("16. tan");
- System.out.println("17. Quit");
- scan.hasNextInt();
- options = scan.nextInt();
-
- try{
-
- switch (options){
-
- case 1: //Sum
- //System.out.print('\u000C');
-
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
-
- answer=Math_methods.add(num1,num2);
- System.out.println(answer);
- break;
-
- case 2: //difference:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.minus(num1,num2);
- System.out.println(answer);
- break;
-
- case 3: // multiply:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.mult(num1,num2);
- System.out.println(answer);
- break;
-
- case 4: //divide:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.div(num1,num2);
- System.out.println(answer);
- break;
-
- case 5: //modulus:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.mod(num1,num2);
- System.out.println(answer);
- break;
-
- case 6: //squareRoot:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.sqrt(num1);
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.sqrt(num1);
-
- System.out.println(answer);
- break;
-
- case 7: //Average:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.ave(num1,num2);
- System.out.println(answer);
- break;
-
- case 8: //Exponent:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.exp(num1,num2);
- System.out.println(answer);
- break;
-
- case 9: //Mod:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.mod(num1,num2);
- System.out.println(answer);
- break;
-
- case 10:
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.max(num1,num2);
- System.out.println(answer);
- break;
-
- case 11: //Minimum:
-
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- System.out.println("Enter Number2 ");
- num2 = scan.nextInt();
- answer = Math_methods.min(num1,num2);
- System.out.println(answer);
- break;
-
- case 12: //Absolute value:
- //System.out.print('\u000C');
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.abs(num1);
- System.out.println(answer);
- break;
-
- case 13:
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.round(num1);
- System.out.println(answer);
- break;
-
- case 14:
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.sin(num1);
- System.out.println(answer);
- break;
-
- case 15:
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.cos(num1);
- System.out.println(answer);
- break;
-
- case 16:
- System.out.println("Enter Number1 ");
- num1= scan.nextInt();
-
- answer = Math_methods.tan(num1);
- System.out.println(answer);
- break;
-
- case 17:
- System.exit(0);
- break;
-
- default:
- System.out.println("Hello");
- System.out.print('\u000C');
-
- }
-
- }
- catch(NumberFormatException e){
- //catch(Exception e){
- System.out.printf("Wrong number or not enough numbers");
-
- }
- /* while(options == 0){
- break;
- }*/
- }
- }
-
- /*catch(IOException e){
- System.out.println(error);
- abc.displayErrorMessage("Please Enter 2 digit");
- }
- /*
- public void addNum2(int Number1, int Number2){
-
- calcValue1 = Number1 + Number2;
-
- }
-
- public int getCalcValue(){
-
- return calculationValue;
- */
-
- }
|