Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package easykalkulacka;
- public class Vyhodnocovanie {
- public int vypocet;
- int scitaj(int c1, int c2) {
- return c1 + c2;
- }
- int odcitaj(int c1, int c2) {
- return c1 - c2;
- }
- int vydel(int c1, int c2) {
- if (c2 == 0) vypocet = 0;
- return c1 / c2;
- }
- int vynasob(int c1, int c2) {
- return c1 * c2;
- }
- }
- package easykalkulacka;
- import java.util.Scanner;
- public class EasyKalkulacka {
- public static void main(String[] args) {
- Vyhodnocovanie pocitaj = new Vyhodnocovanie();
- Scanner in = new Scanner(System.in);
- System.out.println("Vitajte v OOP kalkulacke");
- System.out.println("Vyberte operaciu, na vyber je: \n1. '+'\n2. '-'\n3. '/'\n4. '*'");
- int volba = Integer.parseInt(in.nextLine());
- if (volba > 4 || volba < 1)
- System.exit(0);
- System.out.println("Zadajte prve cislo");
- int c1 = Integer.parseInt(in.nextLine());
- System.out.println("Zadajte druhe cislo");
- int c2 = Integer.parseInt(in.nextLine());
- switch (volba) {
- case 1:
- System.out.println(c1 + " + " + c2 + " = " + pocitaj.scitaj(c1, c2));
- break;
- case 2:
- System.out.println(c1 + " - " + c2 + " = " + pocitaj.odcitaj(c1, c2));
- break;
- case 3:
- if (pocitaj.vypocet == 0)
- System.out.println("Nulou sa delit neda");
- else
- System.out.println(c1 + " / " + c2 + " = " + pocitaj.vydel(c1, c2));
- break;
- case 4:
- System.out.println(c1 + " * " + c2 + " " + pocitaj.vynasob(c1, c2));
- break;
- default:
- System.out.println("Neplatna volba");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement