Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class KalkulatorTester {
- public static void main(String [] args){
- Scanner czytnik = new Scanner(System.in);
- System.out.println("Wprowadz a i b");
- int a = czytnik.nextInt();
- int b = czytnik.nextInt();
- Kalkulator wprowadzanieDanych = new Kalkulator();
- wprowadzanieDanych.setValuesA(a);
- wprowadzanieDanych.setValuesB(b);
- System.out.println("Jesli chcesz dodac nacisnij 1 jesli chcesz pomnozyc wcisnij 2 jesli chcesz odjac wcisnij 3 jesli chcesz podzielic wcisnij 4");
- int x = czytnik.nextInt();
- Kalkulator wypisz = new Kalkulator();
- if(x==1){
- System.out.print(wypisz.adding());
- }
- else if(x==2){
- System.out.println(wypisz.multiply());
- }
- else if(x==3) {
- System.out.println(wypisz.substraction());
- }
- else if(x==4) {
- System.out.println(wypisz.disagreement());
- }
- czytnik.close();
- }
- }
- class Kalkulator {
- private int a;
- private int b;
- public void setValuesA(int a) {
- this.a = a;
- }
- public void setValuesB(int b){
- this.b = b;
- }
- public int getValuesA(){
- return a;
- }
- public int getValuesB() {
- return b;
- }
- public int adding() {
- return a+b;
- }
- public int multiply() {
- return a*b;
- }
- public int substraction() {
- return a-b;
- }
- public int disagreement(){
- return a/b;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement