Advertisement
Morogn93

Smuttekk

May 23rd, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.*;
  2. public class KalkulatorTester {
  3.    
  4.     public static void main(String [] args){
  5.                
  6.         Scanner czytnik = new Scanner(System.in);
  7.         System.out.println("Wprowadz a i b");
  8.         int a = czytnik.nextInt();
  9.         int b = czytnik.nextInt();
  10.        
  11.         Kalkulator wprowadzanieDanych = new Kalkulator();
  12.         wprowadzanieDanych.setValuesA(a);
  13.         wprowadzanieDanych.setValuesB(b);
  14.        
  15.        
  16.         System.out.println("Jesli chcesz dodac nacisnij 1 jesli chcesz pomnozyc wcisnij 2 jesli chcesz odjac wcisnij 3 jesli chcesz podzielic wcisnij 4");
  17.         int x = czytnik.nextInt();
  18.         Kalkulator wypisz = new Kalkulator();
  19.         if(x==1){
  20.             System.out.print(wypisz.adding());
  21.            
  22.         }
  23.         else if(x==2){
  24.             System.out.println(wypisz.multiply());
  25.        
  26.         }
  27.         else if(x==3) {
  28.             System.out.println(wypisz.substraction());
  29.            
  30.         }
  31.         else if(x==4) {
  32.             System.out.println(wypisz.disagreement());
  33.            
  34.         }
  35.        
  36.         czytnik.close();
  37.                                    
  38.     }
  39.  
  40. }
  41.  
  42. class Kalkulator {
  43.  
  44.     private int a;
  45.     private int b;
  46.     public void setValuesA(int a) {
  47.         this.a = a;
  48.     }
  49.     public void setValuesB(int b){
  50.         this.b = b;
  51.     }
  52.    
  53.     public int getValuesA(){
  54.         return a;
  55.     }
  56.     public int getValuesB() {
  57.         return b;
  58.     }
  59.    
  60.     public int adding() {
  61.         return a+b;
  62.     }
  63.    
  64.     public int multiply() {
  65.         return a*b;    
  66.        
  67.     }
  68.     public int substraction() {
  69.         return a-b;
  70.        
  71.     }
  72.     public int disagreement(){
  73.         return a/b;
  74.     }
  75.    
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement