Advertisement
Guest User

Kalkulacka 1.2

a guest
Jul 5th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package easykalkulacka;
  2.  
  3. public class Vyhodnocovanie {
  4.    
  5.     public int vypocet;
  6.    
  7.     int scitaj(int c1, int c2) {
  8.         return c1 + c2;  
  9.     }  
  10.    
  11.     int odcitaj(int c1, int c2) {
  12.         return c1 - c2;
  13.     }
  14.    
  15.     int vydel(int c1, int c2) {
  16.         if (c2 == 0) vypocet = 0;
  17.         return c1 / c2;
  18.     }
  19.    
  20.     int vynasob(int c1, int c2) {
  21.         return c1 * c2;        
  22.     }  
  23. }
  24.  
  25.  
  26. package easykalkulacka;
  27.  
  28. import java.util.Scanner;
  29.  
  30. public class EasyKalkulacka {
  31.  
  32.     public static void main(String[] args) {
  33.         Vyhodnocovanie pocitaj = new Vyhodnocovanie();
  34.         Scanner in = new Scanner(System.in);
  35.        
  36.         System.out.println("Vitajte v OOP kalkulacke");
  37.         System.out.println("Vyberte operaciu, na vyber je: \n1. '+'\n2. '-'\n3. '/'\n4. '*'");        
  38.        
  39.         int volba = Integer.parseInt(in.nextLine());
  40.         if (volba > 4 || volba < 1)
  41.             System.exit(0);
  42.        
  43.         System.out.println("Zadajte prve cislo");
  44.         int c1 = Integer.parseInt(in.nextLine());
  45.         System.out.println("Zadajte druhe cislo");
  46.         int c2 = Integer.parseInt(in.nextLine());
  47.        
  48.        
  49.         switch (volba) {
  50.             case 1:
  51.                 System.out.println(c1 + " + " + c2 + " = " + pocitaj.scitaj(c1, c2));
  52.                 break;
  53.             case 2:
  54.                 System.out.println(c1 + " - " + c2 + " = " + pocitaj.odcitaj(c1, c2));
  55.                 break;
  56.             case 3:
  57.                 if (pocitaj.vypocet == 0)
  58.                     System.out.println("Nulou sa delit neda");
  59.                 else    
  60.                     System.out.println(c1 + " / " + c2 + " = " + pocitaj.vydel(c1, c2));
  61.                 break;
  62.             case 4:
  63.                 System.out.println(c1 + " * " + c2 + " " + pocitaj.vynasob(c1, c2));
  64.                 break;
  65.             default:
  66.                 System.out.println("Neplatna volba");
  67.         }                    
  68.     }  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement