NoNameCracksInc

Java Calculator Extended

Feb 19th, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.17 KB | None | 0 0
  1. Multi-functional java calculator.You can count your average, convert euro into any other currency or use casual calculator using basic operations +,-,*,/.Enjoy!
  2.  
  3. import java.util.*;
  4. import java.io.* ;
  5.  
  6. class start {
  7.    static String again;
  8.    static float div;
  9.    public static BufferedReader reader;
  10.    public static void main (String args[]) throws IOException {
  11.    reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.            System.out.println('\n' + "Vlozte (1) pre kalkulacky, (2) pre priemer.");
  14.            String dec1 = reader.readLine();
  15.            int dec2 = Integer.parseInt(dec1);
  16.              if (dec2 == 1) {
  17.              do {
  18.          System.out.println("Vlozte (1) pre numericku kalkulacku, (2) pre euro kalkulacku:");
  19.          String decision = reader.readLine();
  20.          int decision2 = Integer.parseInt(decision);
  21.          if(decision2 == 1) {
  22.          System.out.println('\n' + "Vybrali ste si numericku kalkulacku.");
  23.          
  24.          
  25.  
  26.       System.out.println("Vloz prve cislo:");
  27.       String num1 = reader.readLine();
  28.       float n1 = Float.parseFloat(num1);
  29.  
  30.         System.out.println("Vyber si operaciu: (+, -, *, /)");
  31.         String op1 = reader.readLine();
  32.         char op2 = op1.charAt(0);
  33.              
  34.           System.out.println("Vloz druhe cislo:");
  35.           String num2 = reader.readLine();
  36.           float n2 = Float.parseFloat(num2);
  37.            
  38.            try {          
  39.            if (op2 == '+') {
  40.             float plus;
  41.             plus = n1+n2;
  42.             System.out.println('\n'+ "Sucet je: " + plus);
  43.                            } // ends IF statement.
  44.                } // ends try.
  45.       catch(ArithmeticException v) {
  46.             System.out.println("Chyba: " + v.getMessage());
  47.                                    } // ends catch.
  48.                      
  49.            try {                
  50.            if (op2 == '-') {
  51.             float minus;
  52.             minus = n1-n2;
  53.             System.out.println('\n'+ "Rozdiel je: " + minus + ".");
  54.                            }
  55.                }
  56.       catch (ArithmeticException v) {
  57.              System.out.println("Chyba: " + v);
  58.                                     }
  59.                      
  60.            try {
  61.            if (op2 == '*') {
  62.             float mult;
  63.             mult = n1*n2;
  64.             System.out.println('\n'+ "Sucin je: " + mult + ".");
  65.                            }
  66.                }
  67.       catch (ArithmeticException v) {
  68.              System.out.println("Chyba: " + v);
  69.                                     }
  70.                      
  71.            try {
  72.            if (op2 == '/' && n2 == 0)
  73.             throw new ArithmeticException ("Delenie nulou.");  
  74.            if (op2 == '/' && n2 != 0) {
  75.             div = n1/n2;
  76.             System.out.println('\n'+ "Podiel je: " + div + ".");          
  77.                                       } // ends IF statement.
  78.                } // ends try.
  79.        catch (ArithmeticException v) {
  80.              System.out.println("Chyba: " + v.getMessage());
  81.                                     } // ends catch.
  82.          } // ends higher numeric calculation IF statement.
  83.  
  84.      
  85.      
  86.       if (decision2 == 2) {
  87.        System.out.println('\n' + "Vybrali ste si euro kalkulacku.");
  88.        System.out.println("Vlozte pocet eur: ");
  89.        String euro = reader.readLine();
  90.        int euro2 = Integer.parseInt(euro);
  91.        
  92.            try {
  93.            if (euro2 == 0 || euro2 > 4)
  94.             System.out.println(euro2 + " eur je priblizne " + euro2*30 + " korun.");
  95.            if (euro2 == 1)
  96.             System.out.println(euro2 + " euro je priblizne " + euro2*30 + " korun.");
  97.            if (euro2 == 2 || euro2 == 3 || euro2 == 4)
  98.             System.out.println(euro2 + " eura su priblizne " + euro2*30 + " korun.");
  99.                } // ends try before catch.
  100.       catch (ArithmeticException v) {
  101.              System.out.println("Chyba: " + v);
  102.                                     } // ends catch.
  103.                           } // ends higher euro calculation IF statement.
  104.    
  105.       System.out.println('\n' + "Opakovat?. a/n");
  106.       again = reader.readLine();
  107.              } // ends do.
  108.  
  109.       while (!again.equals("n"));
  110.              System.exit(0);
  111.              } // ends higher calculation IF statement.
  112.            
  113.            
  114.       do {
  115.       if (dec2 == 2) {
  116.            System.out.println('\n' + "Vybrali ste si priemer znamok.");
  117.        System.out.println("Vyberte si Vas pocet znamok (2-5):");
  118.                      } // ends higher IF statement.
  119.        String pocet1 = reader.readLine();
  120.        int pocet2 = Integer.parseInt(pocet1);
  121.      
  122.            try {
  123.            if (pocet2 < 6 && pocet2 > 1) {
  124.            if (pocet2 == 5) {            
  125.             System.out.println("Vlozte prve cislo:");
  126.             String c1 = reader.readLine();
  127.             float c2 = Float.parseFloat(c1);
  128.      
  129.              System.out.println("Vlozte druhe cislo:");
  130.              String c3 = reader.readLine();
  131.              float c4 = Float.parseFloat(c3);
  132.      
  133.               System.out.println("Vlozte tretie cislo:");
  134.               String c5 = reader.readLine();
  135.               float c6 = Float.parseFloat(c5);
  136.      
  137.                System.out.println("Vlozte stvrte cislo:");
  138.                String c7 = reader.readLine();
  139.                float c8 = Float.parseFloat(c7);
  140.      
  141.                 System.out.println("Vlozte piate cislo:");
  142.                 String c9 = reader.readLine();
  143.                 float c10 = Float.parseFloat(c9);
  144.      
  145.       System.out.println("Vas priemer je: " + (c2 + c4 + c6 + c8 + c10)/5);
  146.                             } // ends lower IF statement.
  147.      
  148.            if (pocet2 == 4) {
  149.                 System.out.println("Vlozte prve cislo:");
  150.                 String c11 = reader.readLine();
  151.                 float c12 = Float.parseFloat(c11);
  152.                  
  153.                  System.out.println("Vlozte druhe cislo:");
  154.                  String c13 = reader.readLine();
  155.                  float c14 = Float.parseFloat(c13);
  156.                  
  157.                   System.out.println("Vlozte tretie cislo:");
  158.                   String c15 = reader.readLine();
  159.                   float c16 = Float.parseFloat(c15);
  160.                  
  161.                    System.out.println("Vlozte stvrte cislo:");
  162.                    String c17 = reader.readLine();
  163.                    float c18 = Float.parseFloat(c17);
  164.              
  165.           System.out.println("Vas priemer je: " + (c12+c14+c16+c18)/4);
  166.                              } // ends lower IF statement.
  167.      
  168.                if (pocet2 == 3) {
  169.                 System.out.println("Vlozte prve cislo:");
  170.                 String c19 = reader.readLine();
  171.                 float c20 = Float.parseFloat(c19);
  172.                  
  173.                  System.out.println("Vlozte druhe cislo:");
  174.                  String c21 = reader.readLine();
  175.              float c22 = Float.parseFloat(c21);
  176.                  
  177.               System.out.println("Vlozte tretie cislo:");
  178.               String c23 = reader.readLine();
  179.                   float c24 = Float.parseFloat(c23);
  180.          
  181.           System.out.println("Vas priemer je: " + (c20 + c22 + c24)/3);
  182.                                 } // ends lower IF statement.
  183.              
  184.            if (pocet2 == 2) {
  185.             System.out.println("Vlozte prve cislo:");
  186.             String c25 = reader.readLine();
  187.             float c26 = Float.parseFloat(c25);
  188.                  
  189.              System.out.println("Vlozte druhe cislo:");
  190.              String c27 = reader.readLine();
  191.              float c28 = Float.parseFloat(c27);
  192.      
  193.       System.out.println("Vas priemer je: " + (c26 + c28)/2);
  194.                             } // ends lower IF statement.
  195.            
  196.            System.out.println('\n' + "Opakovat? a/n");
  197.            again = reader.readLine();                        
  198.                } // ends higher average IF statement.
  199.                } // ends try before catch.
  200.       catch (ArithmeticException v) {
  201.              System.out.println("Chyba: " + v);                                  
  202.                } // ends catch.
  203.                } // ends do.
  204.      
  205.            while(!again.equals("n"));
  206.                  System.exit(0);
  207.  }
  208. }
Advertisement
Add Comment
Please, Sign In to add comment