Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Multi-functional java calculator.You can count your average, convert euro into any other currency or use casual calculator using basic operations +,-,*,/.Enjoy!
- import java.util.*;
- import java.io.* ;
- class start {
- static String again;
- static float div;
- public static BufferedReader reader;
- public static void main (String args[]) throws IOException {
- reader = new BufferedReader(new InputStreamReader(System.in));
- System.out.println('\n' + "Vlozte (1) pre kalkulacky, (2) pre priemer.");
- String dec1 = reader.readLine();
- int dec2 = Integer.parseInt(dec1);
- if (dec2 == 1) {
- do {
- System.out.println("Vlozte (1) pre numericku kalkulacku, (2) pre euro kalkulacku:");
- String decision = reader.readLine();
- int decision2 = Integer.parseInt(decision);
- if(decision2 == 1) {
- System.out.println('\n' + "Vybrali ste si numericku kalkulacku.");
- System.out.println("Vloz prve cislo:");
- String num1 = reader.readLine();
- float n1 = Float.parseFloat(num1);
- System.out.println("Vyber si operaciu: (+, -, *, /)");
- String op1 = reader.readLine();
- char op2 = op1.charAt(0);
- System.out.println("Vloz druhe cislo:");
- String num2 = reader.readLine();
- float n2 = Float.parseFloat(num2);
- try {
- if (op2 == '+') {
- float plus;
- plus = n1+n2;
- System.out.println('\n'+ "Sucet je: " + plus);
- } // ends IF statement.
- } // ends try.
- catch(ArithmeticException v) {
- System.out.println("Chyba: " + v.getMessage());
- } // ends catch.
- try {
- if (op2 == '-') {
- float minus;
- minus = n1-n2;
- System.out.println('\n'+ "Rozdiel je: " + minus + ".");
- }
- }
- catch (ArithmeticException v) {
- System.out.println("Chyba: " + v);
- }
- try {
- if (op2 == '*') {
- float mult;
- mult = n1*n2;
- System.out.println('\n'+ "Sucin je: " + mult + ".");
- }
- }
- catch (ArithmeticException v) {
- System.out.println("Chyba: " + v);
- }
- try {
- if (op2 == '/' && n2 == 0)
- throw new ArithmeticException ("Delenie nulou.");
- if (op2 == '/' && n2 != 0) {
- div = n1/n2;
- System.out.println('\n'+ "Podiel je: " + div + ".");
- } // ends IF statement.
- } // ends try.
- catch (ArithmeticException v) {
- System.out.println("Chyba: " + v.getMessage());
- } // ends catch.
- } // ends higher numeric calculation IF statement.
- if (decision2 == 2) {
- System.out.println('\n' + "Vybrali ste si euro kalkulacku.");
- System.out.println("Vlozte pocet eur: ");
- String euro = reader.readLine();
- int euro2 = Integer.parseInt(euro);
- try {
- if (euro2 == 0 || euro2 > 4)
- System.out.println(euro2 + " eur je priblizne " + euro2*30 + " korun.");
- if (euro2 == 1)
- System.out.println(euro2 + " euro je priblizne " + euro2*30 + " korun.");
- if (euro2 == 2 || euro2 == 3 || euro2 == 4)
- System.out.println(euro2 + " eura su priblizne " + euro2*30 + " korun.");
- } // ends try before catch.
- catch (ArithmeticException v) {
- System.out.println("Chyba: " + v);
- } // ends catch.
- } // ends higher euro calculation IF statement.
- System.out.println('\n' + "Opakovat?. a/n");
- again = reader.readLine();
- } // ends do.
- while (!again.equals("n"));
- System.exit(0);
- } // ends higher calculation IF statement.
- do {
- if (dec2 == 2) {
- System.out.println('\n' + "Vybrali ste si priemer znamok.");
- System.out.println("Vyberte si Vas pocet znamok (2-5):");
- } // ends higher IF statement.
- String pocet1 = reader.readLine();
- int pocet2 = Integer.parseInt(pocet1);
- try {
- if (pocet2 < 6 && pocet2 > 1) {
- if (pocet2 == 5) {
- System.out.println("Vlozte prve cislo:");
- String c1 = reader.readLine();
- float c2 = Float.parseFloat(c1);
- System.out.println("Vlozte druhe cislo:");
- String c3 = reader.readLine();
- float c4 = Float.parseFloat(c3);
- System.out.println("Vlozte tretie cislo:");
- String c5 = reader.readLine();
- float c6 = Float.parseFloat(c5);
- System.out.println("Vlozte stvrte cislo:");
- String c7 = reader.readLine();
- float c8 = Float.parseFloat(c7);
- System.out.println("Vlozte piate cislo:");
- String c9 = reader.readLine();
- float c10 = Float.parseFloat(c9);
- System.out.println("Vas priemer je: " + (c2 + c4 + c6 + c8 + c10)/5);
- } // ends lower IF statement.
- if (pocet2 == 4) {
- System.out.println("Vlozte prve cislo:");
- String c11 = reader.readLine();
- float c12 = Float.parseFloat(c11);
- System.out.println("Vlozte druhe cislo:");
- String c13 = reader.readLine();
- float c14 = Float.parseFloat(c13);
- System.out.println("Vlozte tretie cislo:");
- String c15 = reader.readLine();
- float c16 = Float.parseFloat(c15);
- System.out.println("Vlozte stvrte cislo:");
- String c17 = reader.readLine();
- float c18 = Float.parseFloat(c17);
- System.out.println("Vas priemer je: " + (c12+c14+c16+c18)/4);
- } // ends lower IF statement.
- if (pocet2 == 3) {
- System.out.println("Vlozte prve cislo:");
- String c19 = reader.readLine();
- float c20 = Float.parseFloat(c19);
- System.out.println("Vlozte druhe cislo:");
- String c21 = reader.readLine();
- float c22 = Float.parseFloat(c21);
- System.out.println("Vlozte tretie cislo:");
- String c23 = reader.readLine();
- float c24 = Float.parseFloat(c23);
- System.out.println("Vas priemer je: " + (c20 + c22 + c24)/3);
- } // ends lower IF statement.
- if (pocet2 == 2) {
- System.out.println("Vlozte prve cislo:");
- String c25 = reader.readLine();
- float c26 = Float.parseFloat(c25);
- System.out.println("Vlozte druhe cislo:");
- String c27 = reader.readLine();
- float c28 = Float.parseFloat(c27);
- System.out.println("Vas priemer je: " + (c26 + c28)/2);
- } // ends lower IF statement.
- System.out.println('\n' + "Opakovat? a/n");
- again = reader.readLine();
- } // ends higher average IF statement.
- } // ends try before catch.
- catch (ArithmeticException v) {
- System.out.println("Chyba: " + v);
- } // ends catch.
- } // ends do.
- while(!again.equals("n"));
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment