SHOW:
|
|
- or go back to the newest paste.
| 1 | package easykalkulacka; | |
| 2 | ||
| 3 | public class Vyhodnocovanie {
| |
| 4 | ||
| 5 | - | private int vypocet; |
| 5 | + | public int vypocet; |
| 6 | ||
| 7 | - | void scitaj(int c1, int c2) {
|
| 7 | + | int scitaj(int c1, int c2) {
|
| 8 | - | vypocet = c1 + c2; |
| 8 | + | return c1 + c2; |
| 9 | } | |
| 10 | ||
| 11 | - | void odcitaj(int c1, int c2) {
|
| 11 | + | int odcitaj(int c1, int c2) {
|
| 12 | - | vypocet = c1 - c2; |
| 12 | + | return c1 - c2; |
| 13 | } | |
| 14 | ||
| 15 | - | void vydel(int c1, int c2) {
|
| 15 | + | int vydel(int c1, int c2) {
|
| 16 | - | if (c1 == 0) vypocet = 0; |
| 16 | + | if (c2 == 0) vypocet = 0; |
| 17 | - | else vypocet = c1 / c2; |
| 17 | + | return c1 / c2; |
| 18 | } | |
| 19 | ||
| 20 | - | void vynasob(int c1, int c2) {
|
| 20 | + | int vynasob(int c1, int c2) {
|
| 21 | - | vypocet = c1 * c2; |
| 21 | + | return c1 * c2; |
| 22 | } | |
| 23 | } | |
| 24 | - | int vysledok() {
|
| 24 | + | |
| 25 | - | return vypocet; |
| 25 | + | |
| 26 | - | } |
| 26 | + | |
| 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 | - | pocitaj.scitaj(c1, c2); |
| 55 | + | |
| 56 | - | System.out.println("Vysledok je: " + pocitaj.vysledok());
|
| 56 | + | |
| 57 | if (pocitaj.vypocet == 0) | |
| 58 | System.out.println("Nulou sa delit neda");
| |
| 59 | - | pocitaj.odcitaj(c1, c2); |
| 59 | + | else |
| 60 | - | System.out.println("Vysledok je: " + pocitaj.vysledok());
|
| 60 | + | System.out.println(c1 + " / " + c2 + " = " + pocitaj.vydel(c1, c2)); |
| 61 | break; | |
| 62 | case 4: | |
| 63 | - | pocitaj.vydel(c1, c2); |
| 63 | + | System.out.println(c1 + " * " + c2 + " " + pocitaj.vynasob(c1, c2)); |
| 64 | - | System.out.println("Vysledok je: " + pocitaj.vysledok());
|
| 64 | + | |
| 65 | default: | |
| 66 | System.out.println("Neplatna volba");
| |
| 67 | - | pocitaj.vynasob(c1, c2); |
| 67 | + | |
| 68 | - | System.out.println("Vysledok je: " + pocitaj.vysledok());
|
| 68 | + | |
| 69 | } |